Submission #3046228
Source Code Expand
#include<stdio.h>
int N,Q;
int P[200000],A[200000],B[200000];
int data[100000];
void init_data();
int root(int a);
void unite(int a,int b);
int query(int a,int b);
int main(){
scanf("%d %d",&N,&Q);
for(int i=0;i<Q;i++)scanf("%d %d %d",&P[i],&A[i],&B[i]);
init_data();
for(int i=0;i<Q;i++){
if(P[i]==0)unite(A[i],B[i]);
else {
if(query(A[i],B[i])==1)printf("Yes\n");
else printf("No\n");
}
}
return 0;
}
void init_data(){
for(int i=0;i<100000;i++)data[i]=i;
}
int root(int a){
if(data[a]==a)return a;
else return data[a]=root(data[a]);
}
void unite(int a,int b){
a=root(a);
b=root(b);
if(a==b)return;
data[a]=b;
}
int query(int a,int b){
if(root(a)==root(b))return 1;
else return 0;
}
Submission Info
Submission Time
2018-08-20 04:05:52+0900
Task
B - Union Find
User
tomy
Language
C (GCC 5.4.1)
Score
100
Code Size
773 Byte
Status
AC
Exec Time
54 ms
Memory
3712 KB
Compile Error
./Main.c: In function ‘main’:
./Main.c:13:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&N,&Q);
^
./Main.c:14:22: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
for(int i=0;i<Q;i++)scanf("%d %d %d",&P[i],&A[i],&B[i]);
^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
100 / 100
Status
Set Name
Test Cases
Sample
00_sample_01.txt
All
00_sample_01.txt, subtask_01_01.txt, subtask_01_02.txt, subtask_01_03.txt, subtask_01_04.txt, subtask_01_05.txt, subtask_01_06.txt, subtask_01_07.txt, subtask_01_08.txt, subtask_01_09.txt, subtask_01_10.txt, subtask_01_11.txt, subtask_01_12.txt, subtask_01_13.txt, subtask_01_14.txt, subtask_01_15.txt, subtask_01_16.txt, subtask_01_17.txt, subtask_01_18.txt
Case Name
Status
Exec Time
Memory
00_sample_01.txt
AC
1 ms
512 KB
subtask_01_01.txt
AC
29 ms
2304 KB
subtask_01_02.txt
AC
1 ms
512 KB
subtask_01_03.txt
AC
41 ms
3712 KB
subtask_01_04.txt
AC
50 ms
3456 KB
subtask_01_05.txt
AC
4 ms
768 KB
subtask_01_06.txt
AC
4 ms
768 KB
subtask_01_07.txt
AC
46 ms
3456 KB
subtask_01_08.txt
AC
50 ms
3456 KB
subtask_01_09.txt
AC
1 ms
512 KB
subtask_01_10.txt
AC
1 ms
512 KB
subtask_01_11.txt
AC
43 ms
3456 KB
subtask_01_12.txt
AC
50 ms
3456 KB
subtask_01_13.txt
AC
38 ms
2816 KB
subtask_01_14.txt
AC
1 ms
512 KB
subtask_01_15.txt
AC
44 ms
3456 KB
subtask_01_16.txt
AC
50 ms
3456 KB
subtask_01_17.txt
AC
54 ms
3200 KB
subtask_01_18.txt
AC
50 ms
3200 KB