結果

問題 No.317 辺の追加
ユーザー tjaketjake
提出日時 2015-12-10 14:08:14
言語 Python2
(2.7.18)
結果
TLE  
実行時間 -
コード長 1,145 bytes
コンパイル時間 474 ms
コンパイル使用メモリ 6,584 KB
実行使用メモリ 20,340 KB
最終ジャッジ日時 2023-10-13 10:25:23
合計ジャッジ時間 9,280 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
6,396 KB
testcase_01 AC 13 ms
6,248 KB
testcase_02 AC 866 ms
17,416 KB
testcase_03 AC 612 ms
14,984 KB
testcase_04 TLE -
testcase_05 AC 488 ms
12,164 KB
testcase_06 AC 667 ms
15,124 KB
testcase_07 AC 210 ms
9,208 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
readline = stdin.readline
inputs = lambda: map(int, readline().split())
n, m = inputs()
n1 = n+1

ct = Counter()

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 i in xrange(m):
    u, v = inputs()
    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]
for i, c in enumerate(count):
    if i==root(i):
        ct[count[i]] += 1

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