結果
| 問題 | No.416 旅行会社 |
| コンテスト | |
| ユーザー |
konsin_tokage
|
| 提出日時 | 2018-06-05 07:55:54 |
| 言語 | Python3 (3.14.3 + numpy 2.4.4 + scipy 1.17.1) |
| 結果 |
AC
|
| 実行時間 | 1,508 ms / 4,000 ms |
| コード長 | 667 bytes |
| 記録 | |
| コンパイル時間 | 784 ms |
| コンパイル使用メモリ | 20,676 KB |
| 実行使用メモリ | 89,308 KB |
| 最終ジャッジ日時 | 2026-05-25 12:41:55 |
| 合計ジャッジ時間 | 16,695 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
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)
konsin_tokage