結果
問題 |
No.1451 集団登校
|
ユーザー |
|
提出日時 | 2021-03-25 10:47:38 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 921 bytes |
コンパイル時間 | 1,489 ms |
コンパイル使用メモリ | 178,472 KB |
実行使用メモリ | 13,756 KB |
最終ジャッジ日時 | 2024-11-27 02:29:00 |
合計ジャッジ時間 | 5,453 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 WA * 15 |
ソースコード
#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; }