結果

問題 No.416 旅行会社
ユーザー ヒッキープログラミングするスレヒッキープログラミングするスレ
提出日時 2016-08-28 23:16:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 913 bytes
コンパイル時間 375 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 54,528 KB
最終ジャッジ日時 2024-04-26 17:06:09
合計ジャッジ時間 27,700 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

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]
    print(c,d)
    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