Submission #1069397
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
const int maxn = 200010;
vector<vector<int> > G1(maxn),G2(maxn),G3(maxn);
int N,K,L,ans,ANS[maxn];
int road[maxn];
bool vis1[maxn],vis2[maxn];
void dfs1(int k,int id){
road[k] = id;
vis1[k] = true;
for(int i = 0;i < G1[k].size();++i)
if(!vis1[G1[k][i]]) dfs1(G1[k][i],id);
}
void dfs2(int k){
vis2[k] = true;
ans++;
for(int i = 0;i < G3[k].size();++i)
if(!vis2[G3[k][i]]) dfs2(G3[k][i]);
ANS[k] = ans;
}
int main(){
scanf("%d%d%d",&N,&K,&L);
for(int i = 1;i <= K;++i){
int p,q;
scanf("%d%d",&p,&q);
G1[p].push_back(q);
G1[q].push_back(p);
}
for(int i = 1;i <= L;++i){
int p,q;
scanf("%d%d",&p,&q);
G2[p].push_back(q);
G2[q].push_back(p);
}
int id = 1;
for(int i = 1;i <= N;++i){
if(!vis1[i]){
dfs1(i,id);
id++;
}
}
for(int i = 1;i <= N;++i){
for(int j = 0;j < G2[i].size();++j){
if(road[i] == road[G2[i][j]]){
G3[i].push_back(G2[i][j]);
G3[G2[i][j]].push_back(i);
}
}
}
for(int i = 1;i <= N;++i){
ans = 0;
if(!vis2[i]) dfs2(i);
}
for(int i = 1;i <= N;++i)
printf("%d ",ANS[i]);
return 0;
}
Submission Info
Submission Time |
|
Task |
D - Connectivity |
User |
vjudge1 |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
1341 Byte |
Status |
WA |
Exec Time |
136 ms |
Memory |
24448 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:26:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d",&N,&K,&L);
^
./Main.cpp:29:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&p,&q);
^
./Main.cpp:35:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&p,&q);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 400 |
Status |
|
|
Set Name |
Test Cases |
Sample |
subtask0_0.txt, subtask0_1.txt, subtask0_2.txt |
All |
subtask0_0.txt, subtask0_1.txt, subtask0_2.txt, subtask1_0.txt, subtask1_1.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_2.txt, subtask1_3.txt, subtask1_4.txt, subtask1_5.txt, subtask1_6.txt, subtask1_7.txt, subtask1_8.txt, subtask1_9.txt |
Case Name |
Status |
Exec Time |
Memory |
subtask0_0.txt |
AC |
21 ms |
14336 KB |
subtask0_1.txt |
AC |
21 ms |
14336 KB |
subtask0_2.txt |
AC |
21 ms |
14336 KB |
subtask1_0.txt |
WA |
66 ms |
19200 KB |
subtask1_1.txt |
WA |
96 ms |
21504 KB |
subtask1_10.txt |
WA |
70 ms |
19712 KB |
subtask1_11.txt |
WA |
92 ms |
21120 KB |
subtask1_12.txt |
WA |
113 ms |
23552 KB |
subtask1_13.txt |
WA |
115 ms |
22400 KB |
subtask1_14.txt |
WA |
136 ms |
24448 KB |
subtask1_2.txt |
WA |
104 ms |
22656 KB |
subtask1_3.txt |
WA |
115 ms |
22656 KB |
subtask1_4.txt |
WA |
127 ms |
24448 KB |
subtask1_5.txt |
WA |
73 ms |
19456 KB |
subtask1_6.txt |
WA |
88 ms |
20864 KB |
subtask1_7.txt |
WA |
105 ms |
23296 KB |
subtask1_8.txt |
WA |
107 ms |
23168 KB |
subtask1_9.txt |
WA |
133 ms |
24064 KB |