#23028: c++ AC


es811066 (ZIhan)

學校 : 國立臺灣海洋大學
編號 : 108578
來源 : [210.71.40.108]
最後登入時間 :
2023-12-05 16:29:56
a445. 新手訓練系列- 我的朋友很少 -- 新手訓練系列 ~ 4 | From: [61.220.150.251] | 發表日期 : 2020-10-18 11:28

#include

using namespace std;

int r[100000];

int f(int x){

if(r[x]==x){

return x;

}

return r[x]=f(r[x]);

}

int main(){

int n,k,l;

std::ios::sync_with_stdio(false);

    std::cin.tie(0);

while(cin>>n>>k>>l){

for(int i=0;i<n;i++)r[i]=i;

int a,b;

for(int i=1;i<=k;i++){

cin>>a>>b;

a=f(a);

b=f(b);

if(a==b)continue;

r[b]=a;

}

while(l--){

cin>>a>>b;

if(f(a)==f(b))cout<<":)"<<endl;

else cout<<":("<<endl;

}

}

}

 
ZeroJudge Forum