結果

問題 No.1451 集団登校
ユーザー 沙耶花沙耶花
提出日時 2021-03-31 14:47:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 287 ms / 2,000 ms
コード長 1,070 bytes
コンパイル時間 4,335 ms
コンパイル使用メモリ 271,064 KB
実行使用メモリ 15,296 KB
最終ジャッジ日時 2023-08-21 11:13:59
合計ジャッジ時間 9,753 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 287 ms
15,296 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 150 ms
9,416 KB
testcase_11 AC 136 ms
9,624 KB
testcase_12 AC 136 ms
8,636 KB
testcase_13 AC 179 ms
9,740 KB
testcase_14 AC 179 ms
8,656 KB
testcase_15 AC 104 ms
6,660 KB
testcase_16 AC 156 ms
8,320 KB
testcase_17 AC 47 ms
4,380 KB
testcase_18 AC 63 ms
5,532 KB
testcase_19 AC 82 ms
7,172 KB
testcase_20 AC 183 ms
8,568 KB
testcase_21 AC 29 ms
4,376 KB
testcase_22 AC 32 ms
4,376 KB
testcase_23 AC 8 ms
4,376 KB
testcase_24 AC 144 ms
9,132 KB
testcase_25 AC 95 ms
6,320 KB
testcase_26 AC 156 ms
8,752 KB
testcase_27 AC 108 ms
5,732 KB
testcase_28 AC 45 ms
4,376 KB
testcase_29 AC 93 ms
6,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000

int main(){
	
	int n,m;
	cin>>n>>m;
	
	dsu D(n);
	
	vector<vector<pair<int,mint>>> v(n);
	rep(i,n)v[i].push_back(make_pair(i,1));
	
	vector<mint> bai(n,1);
	
	rep(i,m){
		int a,b;
		cin>>a>>b;
		a--;b--;
		if(D.same(a,b))continue;
		
		int x = D.leader(a),y = D.leader(b);
		
		if(D.size(x)>D.size(y))swap(x,y);
		
		if(D.size(x)==D.size(y)){
			D.merge(x,y);
			int z = D.leader(x);
			bai[z] /= 2;
			while(v[x^y^z].size()!=0){
				v[x^y^z].back().second *= bai[x^y^z];
				v[x^y^z].back().second /= 2;
				v[x^y^z].back().second /= bai[z];
				v[z].push_back(v[x^y^z].back());
				v[x^y^z].pop_back();
			}
			bai[x^y^z] = 0;
		}
		else{
			v[x].clear();
			D.merge(x,y);
		}
		
	}
	
	vector<mint> ans(n,0);
	rep(i,n){
		rep(j,v[i].size()){
			ans[v[i][j].first] = v[i][j].second * bai[i];
		}
	}
	
	rep(i,n)cout<<ans[i].val()<<endl;
	
    return 0;
}
0