結果

問題 No.1451 集団登校
ユーザー 沙耶花沙耶花
提出日時 2021-03-31 14:34:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 878 bytes
コンパイル時間 4,940 ms
コンパイル使用メモリ 268,616 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-05-08 14:25:28
合計ジャッジ時間 8,404 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 152 ms
11,136 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 WA -
testcase_11 AC 151 ms
9,472 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 176 ms
8,192 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 51 ms
5,376 KB
testcase_18 WA -
testcase_19 AC 91 ms
6,912 KB
testcase_20 AC 183 ms
8,320 KB
testcase_21 AC 31 ms
5,376 KB
testcase_22 AC 33 ms
5,376 KB
testcase_23 AC 9 ms
5,376 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 109 ms
5,760 KB
testcase_28 AC 44 ms
5,376 KB
testcase_29 AC 91 ms
6,144 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<int>> v(n);
	rep(i,n)v[i].push_back(i);
	
	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);
			while(v[x^y^z].size()!=0){
				v[z].push_back(v[x^y^z].back());
				v[x^y^z].pop_back();
			}
		}
		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]] = 1;
			ans[v[i][j]] /= v[i].size();
		}
	}
	
	rep(i,n)cout<<ans[i].val()<<endl;
	
    return 0;
}
0