結果

問題 No.416 旅行会社
ユーザー ヒッキープログラミングするスレヒッキープログラミングするスレ
提出日時 2016-08-28 23:19:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 840 ms / 4,000 ms
コード長 898 bytes
コンパイル時間 1,287 ms
コンパイル使用メモリ 86,688 KB
実行使用メモリ 120,572 KB
最終ジャッジ日時 2023-08-21 10:00:32
合計ジャッジ時間 11,423 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 330 ms
100,860 KB
testcase_01 AC 72 ms
71,128 KB
testcase_02 AC 71 ms
71,160 KB
testcase_03 AC 72 ms
71,036 KB
testcase_04 AC 73 ms
71,228 KB
testcase_05 AC 74 ms
71,164 KB
testcase_06 AC 76 ms
71,244 KB
testcase_07 AC 92 ms
76,092 KB
testcase_08 AC 160 ms
78,536 KB
testcase_09 AC 196 ms
81,692 KB
testcase_10 AC 416 ms
101,628 KB
testcase_11 AC 406 ms
101,492 KB
testcase_12 AC 414 ms
101,584 KB
testcase_13 AC 315 ms
100,628 KB
testcase_14 AC 813 ms
120,572 KB
testcase_15 AC 834 ms
120,500 KB
testcase_16 AC 840 ms
120,544 KB
testcase_17 AC 824 ms
120,424 KB
testcase_18 AC 816 ms
120,140 KB
testcase_19 AC 575 ms
101,164 KB
testcase_20 AC 588 ms
101,256 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