結果

問題 No.317 辺の追加
ユーザー TawaraTawara
提出日時 2015-12-12 12:08:14
言語 PyPy2
(7.3.15)
結果
TLE  
実行時間 -
コード長 752 bytes
コンパイル時間 1,290 ms
コンパイル使用メモリ 77,324 KB
実行使用メモリ 88,272 KB
最終ジャッジ日時 2023-10-13 11:42:52
合計ジャッジ時間 5,732 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
78,244 KB
testcase_01 AC 83 ms
78,236 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
N,M = map(int,raw_input().split())
parent = range(N)
conn_comp = defaultdict(int)
def root(x):
	while x != parent[x]:
		parent[x] = x = parent[parent[x]]
	return x
for i in xrange(M):
	u,v = map(lambda x:root(int(x)-1),raw_input().split())
	parent[u] = v
for i in xrange(N):
	conn_comp[root(i)] += 1
vertex_num = conn_comp.values()
vertex_num.sort(reverse=True)
prev = range(-1,N+1)
ans = [-1 for i in xrange(N+1)]
tmp_max = 0
for n in vertex_num:
	dec = tmp_max = tmp_max + n
	r = []
	while dec > n:
		if ans[dec] == -1:
			if ans[dec-n] != -1:
				ans[dec] = ans[dec-n] + 1
				r.append(dec+1)
			else:
				for i in r:
					prev[i] = dec
				r = []
		dec = prev[dec]
	ans[n] = 0
for i in xrange(N):
	print ans[i+1]
0