結果
問題 |
No.1451 集団登校
|
ユーザー |
|
提出日時 | 2021-03-25 10:50:34 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 204 ms / 2,000 ms |
コード長 | 947 bytes |
コンパイル時間 | 1,526 ms |
コンパイル使用メモリ | 176,840 KB |
実行使用メモリ | 13,696 KB |
最終ジャッジ日時 | 2024-11-27 02:29:09 |
合計ジャッジ時間 | 5,075 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#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; }