結果

問題 No.416 旅行会社
ユーザー ヒッキープログラミングするスレヒッキープログラミングするスレ
提出日時 2016-08-28 23:18:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 2,376 ms / 4,000 ms
コード長 898 bytes
コンパイル時間 500 ms
コンパイル使用メモリ 11,032 KB
実行使用メモリ 51,680 KB
最終ジャッジ日時 2023-08-21 10:00:55
合計ジャッジ時間 22,447 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 857 ms
37,532 KB
testcase_01 AC 16 ms
8,320 KB
testcase_02 AC 16 ms
8,276 KB
testcase_03 AC 16 ms
8,304 KB
testcase_04 AC 16 ms
7,784 KB
testcase_05 AC 16 ms
8,248 KB
testcase_06 AC 17 ms
8,260 KB
testcase_07 AC 21 ms
7,988 KB
testcase_08 AC 36 ms
8,916 KB
testcase_09 AC 109 ms
11,152 KB
testcase_10 AC 1,011 ms
37,244 KB
testcase_11 AC 991 ms
34,292 KB
testcase_12 AC 1,001 ms
34,328 KB
testcase_13 AC 829 ms
34,364 KB
testcase_14 AC 2,341 ms
51,680 KB
testcase_15 AC 2,303 ms
51,444 KB
testcase_16 AC 2,337 ms
51,008 KB
testcase_17 AC 2,376 ms
51,184 KB
testcase_18 AC 2,326 ms
51,500 KB
testcase_19 AC 1,368 ms
37,484 KB
testcase_20 AC 1,377 ms
37,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def getInts():
    return list(map(int, input().split(' ')))

n, m, q = getInts()

f = [[] for _ in range(n + 1)]
e = [0] * (n + 1)

def sek(k,i):
    e[i] = k
    h = [i]
    while len(h) > 0:
        w = []
        for x in h:
            for y in f[x]:
                if e[y] == 0:
                    e[y] = k
                    w.append(y)
        h = w

        
for _ in range(m):
    a, b = getInts()
    f[a].append(b)
    f[b].append(a)

z = []

for i in range(q):
    c, d = getInts()
    f[c].remove(d)
    f[d].remove(c)
    z.append([c,d])

sek(-1, 1)
    
for i in range(q):
    c, d = z[q - i - 1]
    f[c].append(d)
    f[d].append(c)
    if e[c] == 0 and e[d] != 0:
        sek(q - i, c)
    if e[d] == 0 and e[c] != 0:
        sek(q - i, d)
        
for i in range(2, n + 1):
    if e[i] == 0:
        print(0)
    elif e[i] > q:
        print(-1)
    else:
        print(e[i])
0