結果

問題 No.317 辺の追加
ユーザー TawaraTawara
提出日時 2015-12-13 14:48:55
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 433 ms / 2,000 ms
コード長 866 bytes
コンパイル時間 1,868 ms
コンパイル使用メモリ 77,656 KB
実行使用メモリ 96,984 KB
最終ジャッジ日時 2023-10-13 14:55:24
合計ジャッジ時間 16,906 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
79,136 KB
testcase_01 AC 83 ms
78,868 KB
testcase_02 AC 288 ms
84,532 KB
testcase_03 AC 286 ms
84,284 KB
testcase_04 AC 337 ms
86,016 KB
testcase_05 AC 259 ms
83,524 KB
testcase_06 AC 306 ms
84,772 KB
testcase_07 AC 181 ms
83,248 KB
testcase_08 AC 433 ms
89,328 KB
testcase_09 AC 308 ms
84,928 KB
testcase_10 AC 351 ms
84,240 KB
testcase_11 AC 241 ms
96,984 KB
testcase_12 AC 353 ms
84,148 KB
testcase_13 AC 278 ms
91,828 KB
testcase_14 AC 323 ms
84,680 KB
testcase_15 AC 344 ms
84,112 KB
testcase_16 AC 333 ms
86,156 KB
testcase_17 AC 325 ms
84,528 KB
testcase_18 AC 353 ms
84,180 KB
testcase_19 AC 355 ms
84,612 KB
testcase_20 AC 364 ms
87,472 KB
testcase_21 AC 177 ms
83,140 KB
testcase_22 AC 157 ms
82,552 KB
testcase_23 AC 166 ms
83,140 KB
testcase_24 AC 198 ms
83,280 KB
testcase_25 AC 185 ms
83,232 KB
testcase_26 AC 187 ms
82,996 KB
testcase_27 AC 176 ms
83,092 KB
testcase_28 AC 164 ms
83,652 KB
testcase_29 AC 129 ms
82,280 KB
testcase_30 AC 367 ms
84,068 KB
testcase_31 AC 344 ms
83,864 KB
testcase_32 AC 375 ms
83,676 KB
testcase_33 AC 372 ms
84,008 KB
testcase_34 AC 378 ms
84,020 KB
testcase_35 AC 381 ms
84,004 KB
testcase_36 AC 329 ms
83,928 KB
testcase_37 AC 335 ms
83,584 KB
testcase_38 AC 375 ms
83,852 KB
testcase_39 AC 377 ms
83,948 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))
	tmp = mul = 1
	for i in xrange(log_num):
		w = v_num*mul
		for j in xrange(N,w-1,-1):
			tmp = ans[j-w]+mul
			if ans[j] > tmp: ans[j] = tmp
		num -= mul; mul *= 2
	if num > 0:
		w = v_num*num
		for j in xrange(N,w-1,-1):
			tmp = ans[j-w]+num
			if ans[j] > tmp: ans[j] = tmp
			
for i in xrange(1,N+1):
	print ans[i]*(ans[i]<N)-1
0