結果
問題 | No.1451 集団登校 |
ユーザー | Californiumer |
提出日時 | 2021-03-14 16:34:09 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 251 ms / 2,000 ms |
コード長 | 788 bytes |
コンパイル時間 | 1,591 ms |
コンパイル使用メモリ | 168,312 KB |
実行使用メモリ | 13,936 KB |
最終ジャッジ日時 | 2024-04-24 00:46:02 |
合計ジャッジ時間 | 6,144 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
8,212 KB |
testcase_01 | AC | 4 ms
8,320 KB |
testcase_02 | AC | 4 ms
8,448 KB |
testcase_03 | AC | 4 ms
8,320 KB |
testcase_04 | AC | 3 ms
8,300 KB |
testcase_05 | AC | 5 ms
8,192 KB |
testcase_06 | AC | 4 ms
8,320 KB |
testcase_07 | AC | 4 ms
8,136 KB |
testcase_08 | AC | 190 ms
13,700 KB |
testcase_09 | AC | 5 ms
8,064 KB |
testcase_10 | AC | 154 ms
13,696 KB |
testcase_11 | AC | 133 ms
13,936 KB |
testcase_12 | AC | 145 ms
13,096 KB |
testcase_13 | AC | 223 ms
13,924 KB |
testcase_14 | AC | 248 ms
12,928 KB |
testcase_15 | AC | 120 ms
11,264 KB |
testcase_16 | AC | 188 ms
12,928 KB |
testcase_17 | AC | 55 ms
8,448 KB |
testcase_18 | AC | 73 ms
10,368 KB |
testcase_19 | AC | 84 ms
11,776 KB |
testcase_20 | AC | 251 ms
12,892 KB |
testcase_21 | AC | 33 ms
8,320 KB |
testcase_22 | AC | 38 ms
8,944 KB |
testcase_23 | AC | 12 ms
8,320 KB |
testcase_24 | AC | 145 ms
13,568 KB |
testcase_25 | AC | 113 ms
11,136 KB |
testcase_26 | AC | 185 ms
13,100 KB |
testcase_27 | AC | 133 ms
10,496 KB |
testcase_28 | AC | 54 ms
9,472 KB |
testcase_29 | AC | 115 ms
10,744 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll=long long; constexpr ll MOD=1e9+7; int dat[100005]; ll p[100005]; set<int>grp[100005]; void UF_init(int N){ fill(dat,dat+N,-1); fill(p,p+N,1); for(int i=0;i<N;i++)grp[i].insert(i); } int find(int x){ return dat[x]<0?x:dat[x]=find(dat[x]); } void unite(int x,int y){ x=find(x);y=find(y); if(x==y)return; if(dat[x]>dat[y])swap(x,y); if(dat[x]==dat[y]){ for(int i:grp[x])(p[i]*=500000004)%=MOD; for(int i:grp[y])(p[i]*=500000004)%=MOD; }else{ for(int i:grp[y])p[i]=0; } for(int i:grp[y])grp[x].insert(i); grp[y].clear(); dat[x]+=dat[y];dat[y]=x; } int main(){ int N,M;cin>>N>>M; UF_init(N); while(M--){ int A,B;cin>>A>>B; unite(A-1,B-1); } for(int i=0;i<N;i++)cout<<p[i]<<endl; }