結果

問題 No.317 辺の追加
ユーザー tjaketjake
提出日時 2015-12-10 14:19:50
言語 Python2
(2.7.18)
結果
TLE  
実行時間 -
コード長 1,074 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 6,504 KB
実行使用メモリ 47,860 KB
最終ジャッジ日時 2023-10-13 10:25:34
合計ジャッジ時間 10,129 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
6,316 KB
testcase_01 AC 13 ms
6,264 KB
testcase_02 AC 901 ms
33,152 KB
testcase_03 AC 670 ms
37,864 KB
testcase_04 TLE -
testcase_05 AC 548 ms
41,980 KB
testcase_06 AC 736 ms
47,860 KB
testcase_07 AC 219 ms
19,136 KB
testcase_08 TLE -
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 deque, Counter
from sys import stdin, stdout
ss = [map(int, s.split()) for s in stdin.readlines()]
n, m = ss[0]
n1 = n+1

parent = [1] + range(1,n1)
count = [1]*n1
def root(x):
    p = parent[x]
    if x!=p:
        parent[x] = x = root(p)
    return x
for u, v in ss[1:]:
    a = root(u); b = root(v)
    if a!=b:
        if a<b:
            parent[b] = a
            count[a] += count[b]
        else:
            parent[a] = b
            count[b] += count[a]
ct = Counter(c for i, c in enumerate(count) if parent[i]==i)

deq = deque()
clear = deq.clear
pop = deq.pop
popleft = deq.popleft
append = deq.append

dp = [-1]+[n]*n
for i, c in ct.items():
    for a in xrange(i):
        clear()
        for j, idx in enumerate(range(a, n1, i)):
            p = (dp[idx]-j, -j)
            while deq and p <= deq[-1]:
                pop()
            append(p)
            v, u = deq[0]
            dp[idx] = v + j
            if c==j+u:
                popleft()

dp = [v if v!=n else -1 for v in dp]
stdout.write("\n".join(map(str, dp[1:])) + "\n")
0