#17396: 請問錯哪裡??


tzuchunchen1015@gmail.com (TCC)

學校 : 不指定學校
編號 : 93686
來源 : [1.173.194.102]
最後登入時間 :
2025-04-23 16:53:10

#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

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

4 3 1

3 4

2 4

1 4

2 1