結果

問題 No.416 旅行会社
ユーザー konsin_tokage
提出日時 2018-06-05 07:55:54
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 2,594 ms / 4,000 ms
コード長 667 bytes
コンパイル時間 231 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 85,760 KB
最終ジャッジ日時 2024-12-14 20:30:47
合計ジャッジ時間 25,307 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
n, m, q = map(int, input().split())
g = [set() for _ in range(n+1)]
for _ in range(m):
    a, b = map(int, input().split())
    g[a].add(b)
    g[b].add(a)
e = []
for _ in range(q):
    a, b = map(int, input().split())
    g[a].remove(b)
    g[b].remove(a)
    e.append((a,b))
g = [list(s) for s in g]
r = [0]*(n+1)
def bfs(i, x):
    q = deque([i])
    while q:
        j = q.popleft()
        if r[j] != 0:
            continue
        r[j] = x
        q.extend(g[j])
bfs(1, -1)
for i, j in e[::-1]:
    g[i].append(j)
    g[j].append(i)
    if not r[i]==r[j]==0:
        bfs(i, q)
        bfs(j, q)
    q -= 1
for i in r[2:]:
    print(i)
0