結果

問題 No.1451 集団登校
ユーザー shiomusubi496shiomusubi496
提出日時 2021-03-25 10:47:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 921 bytes
コンパイル時間 2,810 ms
コンパイル使用メモリ 174,624 KB
実行使用メモリ 13,508 KB
最終ジャッジ日時 2023-08-18 00:50:44
合計ジャッジ時間 7,662 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 189 ms
11,416 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 154 ms
13,108 KB
testcase_11 AC 143 ms
13,508 KB
testcase_12 AC 139 ms
12,004 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 83 ms
9,512 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 148 ms
12,720 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
int main(){
    int N,M; cin>>N>>M;
    vector<set<int>>st(N);
    vector<int>root(N);
    vector<ll>ans(N,1);
    for(int i=0;i<N;i++) root[i]=i;
    for(int i=0;i<N;i++) st[i].insert(i);
    for(int i=0;i<M;i++){
        int A,B; cin>>A>>B;
        A=root[A-1]; B=root[B-1];
        if(st[A].size()<st[B].size())swap(A,B);
        if(st[A].size()!=st[B].size()){
            for(int i:st[B]){
                ans[i]=0;
                root[i]=A;
                st[A].insert(i);
            }
            st[B].clear();
        }else{
            for(int i:st[A]) (ans[i]*=500000004)%=mod;
            for(int i:st[B]){
                (ans[i]*=500000004)%=mod;
                root[i]=A;
                st[A].insert(i);
            }
            st[B].clear();
        }
    }
    for(int i=0;i<N;i++) cout<<ans[i]<<endl;
}
0