結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 180 ms
11,412 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 153 ms
13,028 KB
testcase_11 AC 139 ms
13,464 KB
testcase_12 AC 137 ms
11,616 KB
testcase_13 AC 213 ms
13,372 KB
testcase_14 AC 231 ms
11,504 KB
testcase_15 AC 120 ms
8,544 KB
testcase_16 AC 182 ms
11,704 KB
testcase_17 AC 48 ms
4,380 KB
testcase_18 AC 70 ms
6,448 KB
testcase_19 AC 81 ms
9,160 KB
testcase_20 AC 238 ms
11,412 KB
testcase_21 AC 29 ms
4,376 KB
testcase_22 AC 35 ms
4,404 KB
testcase_23 AC 8 ms
4,376 KB
testcase_24 AC 146 ms
12,696 KB
testcase_25 AC 115 ms
8,164 KB
testcase_26 AC 183 ms
11,616 KB
testcase_27 AC 130 ms
7,348 KB
testcase_28 AC 52 ms
5,176 KB
testcase_29 AC 111 ms
7,720 KB
権限があれば一括ダウンロードができます

ソースコード

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(A==B)continue;
        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