結果

問題 No.1451 集団登校
ユーザー kwm_tkwm_t
提出日時 2021-04-02 20:25:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 269 ms / 2,000 ms
コード長 1,353 bytes
コンパイル時間 4,917 ms
コンパイル使用メモリ 236,672 KB
実行使用メモリ 34,632 KB
最終ジャッジ日時 2023-08-25 04:36:42
合計ジャッジ時間 9,227 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 269 ms
34,632 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 34 ms
13,552 KB
testcase_11 AC 19 ms
13,032 KB
testcase_12 AC 34 ms
12,560 KB
testcase_13 AC 87 ms
17,984 KB
testcase_14 AC 125 ms
18,164 KB
testcase_15 AC 53 ms
12,036 KB
testcase_16 AC 80 ms
16,376 KB
testcase_17 AC 19 ms
4,472 KB
testcase_18 AC 25 ms
8,584 KB
testcase_19 AC 13 ms
9,112 KB
testcase_20 AC 124 ms
18,668 KB
testcase_21 AC 12 ms
4,376 KB
testcase_22 AC 16 ms
5,652 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 31 ms
13,312 KB
testcase_25 AC 54 ms
11,720 KB
testcase_26 AC 79 ms
16,196 KB
testcase_27 AC 64 ms
11,080 KB
testcase_28 AC 23 ms
7,008 KB
testcase_29 AC 53 ms
11,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#include "atcoder/all"
using namespace std;
using namespace atcoder;
using mint = modint1000000007;
const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
mint ans[100005];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N, M;
	cin >> N >> M;
	vector<set<int>>st(N);
	rep(i, N) { st[i].insert(i); }
	rep(i, N) { ans[i] = 1; }
	dsu uf(N);
	rep(i, M) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		int x = uf.leader(a);
		int y = uf.leader(b);
		if (x == y) { continue; }
		if (uf.size(a) > uf.size(b)) {
			for (auto s : st[y]) { ans[s] = 0; }
		}
		else if (uf.size(a) < uf.size(b)) {
			for (auto s : st[x]) { ans[s] = 0; }
		}
		else {
			for (auto s : st[x]) { ans[s] /= 2; }
			for (auto s : st[y]) { ans[s] /= 2; }
		}
		uf.merge(a, b);
		if (x == uf.leader(a)) {
			for (auto s : st[y]) { st[x].insert(s); }
		}
		else {
			for (auto s : st[x]) { st[y].insert(s); }
		}
	}
	rep(i, N) { cout << ans[i].val() << endl; }
	return 0;
}
0