結果

問題 No.317 辺の追加
ユーザー TawaraTawara
提出日時 2015-12-12 16:57:59
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 438 ms / 2,000 ms
コード長 811 bytes
コンパイル時間 1,337 ms
コンパイル使用メモリ 77,464 KB
実行使用メモリ 97,284 KB
最終ジャッジ日時 2023-10-13 11:50:24
合計ジャッジ時間 15,230 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
78,952 KB
testcase_01 AC 84 ms
78,944 KB
testcase_02 AC 311 ms
84,184 KB
testcase_03 AC 288 ms
84,336 KB
testcase_04 AC 331 ms
86,180 KB
testcase_05 AC 269 ms
83,532 KB
testcase_06 AC 313 ms
84,088 KB
testcase_07 AC 187 ms
83,344 KB
testcase_08 AC 438 ms
89,388 KB
testcase_09 AC 325 ms
85,100 KB
testcase_10 AC 357 ms
84,568 KB
testcase_11 AC 259 ms
97,284 KB
testcase_12 AC 359 ms
84,636 KB
testcase_13 AC 288 ms
91,668 KB
testcase_14 AC 332 ms
85,196 KB
testcase_15 AC 352 ms
84,308 KB
testcase_16 AC 352 ms
86,484 KB
testcase_17 AC 332 ms
84,492 KB
testcase_18 AC 358 ms
84,276 KB
testcase_19 AC 363 ms
84,144 KB
testcase_20 AC 356 ms
87,460 KB
testcase_21 AC 176 ms
82,928 KB
testcase_22 AC 157 ms
82,836 KB
testcase_23 AC 168 ms
83,092 KB
testcase_24 AC 198 ms
83,612 KB
testcase_25 AC 189 ms
83,488 KB
testcase_26 AC 192 ms
83,108 KB
testcase_27 AC 180 ms
82,980 KB
testcase_28 AC 173 ms
83,276 KB
testcase_29 AC 131 ms
82,336 KB
testcase_30 AC 419 ms
83,940 KB
testcase_31 AC 393 ms
83,848 KB
testcase_32 AC 331 ms
84,404 KB
testcase_33 AC 332 ms
83,816 KB
testcase_34 AC 342 ms
83,884 KB
testcase_35 AC 334 ms
83,936 KB
testcase_36 AC 388 ms
83,536 KB
testcase_37 AC 390 ms
83,908 KB
testcase_38 AC 421 ms
83,844 KB
testcase_39 AC 332 ms
83,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from math import log
parent = range(100000)
def root(x):
	while x != parent[x]: parent[x] = x = parent[parent[x]]
	return x
N,M = map(int,raw_input().split())
conn_comp = defaultdict(int)
comp_num = defaultdict(int)
ans = [N]*(N+1)
ans[0] = 0
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
for v in conn_comp.itervalues(): comp_num[v] += 1
for v_num,num in comp_num.iteritems():
	log_num = int(log(num,2))
	mul = 1
	for i in xrange(log_num):
		w = v_num*mul
		for j in xrange(N,w-1,-1): ans[j] = min(ans[j],ans[j-w]+mul)
		num -= mul
		mul *= 2
	if num > 0:
		w = v_num*num
		for j in xrange(N,w-1,-1): ans[j] = min(ans[j],ans[j-w]+num)
for i in xrange(1,N+1):
	print ans[i]*(ans[i]<N)-1
0