結果
問題 | No.1451 集団登校 |
ユーザー | shiomusubi496 |
提出日時 | 2021-03-14 18:20:44 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 216 ms / 2,000 ms |
コード長 | 1,011 bytes |
コンパイル時間 | 1,555 ms |
コンパイル使用メモリ | 172,408 KB |
実行使用メモリ | 34,816 KB |
最終ジャッジ日時 | 2024-04-24 01:12:03 |
合計ジャッジ時間 | 5,258 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 211 ms
34,816 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 144 ms
14,080 KB |
testcase_11 | AC | 122 ms
13,696 KB |
testcase_12 | AC | 124 ms
13,056 KB |
testcase_13 | AC | 185 ms
18,304 KB |
testcase_14 | AC | 214 ms
18,432 KB |
testcase_15 | AC | 109 ms
12,288 KB |
testcase_16 | AC | 170 ms
16,896 KB |
testcase_17 | AC | 47 ms
5,376 KB |
testcase_18 | AC | 63 ms
8,704 KB |
testcase_19 | AC | 75 ms
9,600 KB |
testcase_20 | AC | 216 ms
18,944 KB |
testcase_21 | AC | 30 ms
5,376 KB |
testcase_22 | AC | 37 ms
5,632 KB |
testcase_23 | AC | 8 ms
5,376 KB |
testcase_24 | AC | 143 ms
13,696 KB |
testcase_25 | AC | 102 ms
11,776 KB |
testcase_26 | AC | 168 ms
16,640 KB |
testcase_27 | AC | 117 ms
11,008 KB |
testcase_28 | AC | 47 ms
7,040 KB |
testcase_29 | AC | 104 ms
11,648 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll=long long; constexpr ll mod=1000000007; struct UnionFind{ vector<int> par; vector<ll> ans; vector<set<int>> st; UnionFind(int n):par(n,-1),ans(n,1),st(n){ for(int i=0;i<n;i++) st[i].insert(i); } int find(int x){ return par[x]<0 ? x : par[x]=find(par[x]); } void unite(int x,int y){ x=find(x); y=find(y); if(x==y)return; if(par[x]>par[y]) swap(x,y); if(par[x]==par[y]){ for(int i:st[x]) ans[i]=ans[i]*500000004%mod; for(int i:st[y]) ans[i]=ans[i]*500000004%mod; }else{ for(int i:st[y]) ans[i]=0; } for(int i:st[y]) st[x].insert(i); par[x]+=par[y]; par[y]=x; } int get(int x){ return ans[x]; } }; int main(){ int N,M; cin>>N>>M; UnionFind UF(N); for(int i=0;i<M;i++){ int A,B; cin>>A>>B; UF.unite(A-1, B-1); } for(int i=0;i<N;i++) cout<<UF.get(i)<<endl; }