結果
問題 | No.1451 集団登校 |
ユーザー |
![]() |
提出日時 | 2021-03-31 22:42:37 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 274 ms / 2,000 ms |
コード長 | 1,757 bytes |
コンパイル時間 | 3,315 ms |
コンパイル使用メモリ | 184,208 KB |
最終ジャッジ日時 | 2025-01-20 04:11:49 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <complex> #include <unordered_map> #include <unordered_set> #include <random> #include <cassert> #include <fstream> #include <utility> #include <functional> #include <time.h> #include <stack> #include <array> #include <list> #include <atcoder/all> #define popcount __builtin_popcount using namespace std; using namespace atcoder; typedef long long ll; typedef pair<int, int> P; int main() { int n, m; cin>>n>>m; using mint=modint1000000007; vector<pair<mint, int>> v[100010]; int par[100010]; for(int i=0; i<n; i++) v[i].push_back(make_pair(mint(1), i)), par[i]=i; for(int i=0; i<m; i++){ int a, b; cin>>a>>b; a--; b--; a=par[a], b=par[b]; if(a==b) continue; if(v[a].size()>v[b].size()) swap(a, b); if(v[a].size()!=v[b].size()){ while(!v[a].empty()){ auto p=v[a].back(); v[a].pop_back(); v[b].push_back(make_pair(mint(0), p.second)); par[p.second]=b; } }else{ for(auto &p:v[b]) p.first/=mint(2); while(!v[a].empty()){ auto p=v[a].back(); v[a].pop_back(); v[b].push_back(make_pair(p.first/mint(2), p.second)); par[p.second]=b; } } } mint ans[100010]; for(int i=0; i<n; i++){ for(auto p:v[i]){ ans[p.second]=p.first; } } for(int i=0; i<n; i++){ cout<<ans[i].val()<<endl; } return 0; }