Submission #1069249
Source Code Expand
#include<cstdio>
#include<queue>
#include<climits>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<ctype.h>
#include<set>
#include<vector>
#include<map>
#include<time.h>
#include<list>
#include<stack>
#include<iostream>
using namespace std;
#define mod 1000000007
#define mem(x,k ) memset(x, (k) ,sizeof(x))
#define mp(A, B) make_pair(A, B)
#define pb push_back
#define sca scanf
#define pri printf
#define fi first
#define se second
typedef long long LL;
typedef long double LD;
typedef pair< int , int > pii;
const LL INFLL=0x3f3f3f3f3f3f3f3fll;
const int INF=0x7fffffff;
const double PI=acos(-1.0);
const double eps=1e-9;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
int n,m,k;
int f[200005];
int f2[200005];
int G[200005];
int Father(int k)
{
if (k==f[k]) return k;
G[ f[k] ] += G[k];
G[k]=0;
return f[k]=Father(f[k]);
}
void Union(int x,int y)
{
if (Father(x)==Father(y)) return;
else
{
G[ f[y] ]+=G[ f [x] ];
G[ f[x] ]=0;
f[ f[x] ]=f[y];
return;
}
}
int Father2(int k)
{
if (k==f2[k]) return k;
return f2[k]=Father2(f2[k]);
}
void Union2(int x,int y)
{
if (Father2(x)==Father2(y)) return;
else
{
f2[ f2[x] ]=f2[y];
return;
}
}
int main(){
scanf("%d%d%d",&n,&k,&m);
for (int i=1;i<=n;i++){
f[i]=f2[i]=i;
G[i]=1;
}
for (int i=1;i<=k;i++){
int u,v;
scanf("%d%d",&u,&v);
Union2(u,v);
}
for (int i=1;i<=m;i++){
int u,v;
scanf("%d%d",&u,&v);
if (Father2(u)==Father2(v)){
Union(u,v);
}
}
for (int i=1;i<=n;i++){
Father(i);
}
for (int i=1;i<=n;i++){
//printf("@%d@",Father(i));
printf("%d",G[ Father(i) ]);
if (i!=n) printf(" ");
}
printf("\n");
return 0;
}
Submission Info
Submission Time |
|
Task |
D - Connectivity |
User |
vjudge1 |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
1890 Byte |
Status |
WA |
Exec Time |
61 ms |
Memory |
2944 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:76:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d",&n,&k,&m);
^
./Main.cpp:83:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&u,&v);
^
./Main.cpp:88:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&u,&v);
^
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 |
3 ms |
256 KB |
subtask0_1.txt |
AC |
3 ms |
256 KB |
subtask0_2.txt |
AC |
3 ms |
256 KB |
subtask1_0.txt |
AC |
32 ms |
256 KB |
subtask1_1.txt |
WA |
56 ms |
2944 KB |
subtask1_10.txt |
AC |
33 ms |
256 KB |
subtask1_11.txt |
WA |
54 ms |
2560 KB |
subtask1_12.txt |
WA |
59 ms |
2816 KB |
subtask1_13.txt |
WA |
56 ms |
2944 KB |
subtask1_14.txt |
WA |
56 ms |
2304 KB |
subtask1_2.txt |
WA |
54 ms |
2304 KB |
subtask1_3.txt |
WA |
58 ms |
2944 KB |
subtask1_4.txt |
WA |
56 ms |
2432 KB |
subtask1_5.txt |
AC |
34 ms |
384 KB |
subtask1_6.txt |
WA |
51 ms |
2432 KB |
subtask1_7.txt |
WA |
58 ms |
2944 KB |
subtask1_8.txt |
WA |
61 ms |
2944 KB |
subtask1_9.txt |
WA |
54 ms |
2048 KB |