#17396: 請問錯哪裡??


tzuchunchen1015@gmail.com (TCC)

學校 : 臺北市立第一女子高級中學
編號 : 93686
來源 : [140.112.217.20]
最後登入時間 :
2023-12-27 11:15:30
a445. 新手訓練系列- 我的朋友很少 -- 新手訓練系列 ~ 4 | From: [219.84.57.240] | 發表日期 : 2019-04-07 12:17

#include <iostream>
using namespace std;
int root[10005];
int main(int argc, char** argv) {

    int n,m,q,a,b;
        while(cin>>n>>m>>q){
            for(int i=1;i<=n;i++)root[i]=i;
            while(m--){
                cin>>a>>b;
                if(a>b)swap(a,b);
                if(root[a]!=root[b])root[b]=root[a];
            }
            while(q--){
                cin>>a>>b;
                if(root[a]==root[b])cout<<":)\n";
                else cout<<":(\n";
            }
    }
    return 0;
}

 
#17397: Re:請問錯哪裡??


qqrainbow (愛蜜莉雅)

學校 : 國立嘉義高級中學
編號 : 83319
來源 : [36.238.5.68]
最後登入時間 :
2023-04-26 23:31:35
a445. 新手訓練系列- 我的朋友很少 -- 新手訓練系列 ~ 4 | From: [1.173.140.202] | 發表日期 : 2019-04-07 14:06

試試這組測資,你就知道了。應該要輸出:)

4 3 1

3 4

2 4

1 4

2 1

 

 
ZeroJudge Forum