Submission #1069245
Source Code Expand
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int fa[200005];
int fa1[200005];
int vis[200005];
int find1(int a)
{
if(fa[a]!=a)
fa[a]=find1(fa[a]);
return fa[a];
}
void union1(int a,int b)
{
fa[find1(a)]=find1(b);
}
int find2(int a)
{
if(fa1[a]!=a)
fa1[a]=find2(fa1[a]);
return fa1[a];
}
void union2(int a,int b)
{
fa1[find2(a)]=find2(b);
}
map<long long,int> mp;
int main()
{
int n,k,l;
cin>>n>>k>>l;
memset(vis,0,sizeof(vis));
for(int i=0;i<=n;i++)
{
fa[i]=i;
fa1[i]=i;
}
for(int i=0;i<k;i++)
{
int l1,r;
scanf("%d %d",&l1,&r);
union1(l1,r);
}
for(int i=0;i<l;i++)
{
int l1,r;
scanf("%d %d",&l1,&r);
//if(find1(l1)==find1(r))
union2(l1,r);
//cout<<find1(l1)<<' '<<find1(r);
}
for(int i=1;i<=n;i++)
{
if(mp.find((long long)((long long)find1(i)*200005+(long long)find2(i)))==mp.end())
mp[(long long)((long long)find1(i)*200005+(long long)find2(i))]=0;
mp[(long long)((long long)find1(i)*200005+(long long)find2(i))]++;
}
for(int i=1;i<n;i++)
printf("%d ",mp[(long long)((long long)find1(i)*200005+(long long)find2(i))]);
printf("%d\n",mp[(long long)((long long)find1(n)*200005+(long long)find2(n))]);
return 0;
}
Submission Info
Submission Time |
|
Task |
D - Connectivity |
User |
vjudge1 |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
1365 Byte |
Status |
AC |
Exec Time |
229 ms |
Memory |
14336 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:45:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&l1,&r);
^
./Main.cpp:51:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&l1,&r);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
400 / 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 |
4 ms |
1024 KB |
subtask0_1.txt |
AC |
4 ms |
1024 KB |
subtask0_2.txt |
AC |
4 ms |
1024 KB |
subtask1_0.txt |
AC |
32 ms |
1024 KB |
subtask1_1.txt |
AC |
229 ms |
14336 KB |
subtask1_10.txt |
AC |
34 ms |
1024 KB |
subtask1_11.txt |
AC |
190 ms |
12928 KB |
subtask1_12.txt |
AC |
122 ms |
12288 KB |
subtask1_13.txt |
AC |
127 ms |
13440 KB |
subtask1_14.txt |
AC |
113 ms |
9600 KB |
subtask1_2.txt |
AC |
97 ms |
9472 KB |
subtask1_3.txt |
AC |
133 ms |
13312 KB |
subtask1_4.txt |
AC |
122 ms |
10496 KB |
subtask1_5.txt |
AC |
34 ms |
1024 KB |
subtask1_6.txt |
AC |
184 ms |
12160 KB |
subtask1_7.txt |
AC |
136 ms |
13440 KB |
subtask1_8.txt |
AC |
139 ms |
13440 KB |
subtask1_9.txt |
AC |
98 ms |
7168 KB |