結果
| 問題 |
No.1647 Travel in Mitaru city 2
|
| コンテスト | |
| ユーザー |
sotanishy
|
| 提出日時 | 2021-08-15 00:18:20 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 803 bytes |
| コンパイル時間 | 271 ms |
| コンパイル使用メモリ | 82,380 KB |
| 実行使用メモリ | 117,380 KB |
| 最終ジャッジ日時 | 2024-10-06 04:10:30 |
| 合計ジャッジ時間 | 17,075 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 WA * 17 |
ソースコード
import sys
input = sys.stdin.readline
H, W, N = map(int, input().split())
G = [[] for _ in range(H+W)]
for i in range(N):
x, y = map(lambda x: int(x) - 1, input().split())
G[x].append((H+y, i))
G[H+y].append((x, i))
prev = [None] * (H+W)
for s in range(H):
if prev[s] is not None:
continue
st = [(s, -1, -1)]
while st:
v, p, j = st.pop()
prev[v] = (p, j)
for u, i in G[v]:
if (u, i) == prev[v]:
continue
if prev[u] is not None:
ans = [i]
while v != s:
v, i = prev[v]
ans.append(i)
print(len(ans))
print(*map(lambda x: x + 1, ans[::-1]))
exit()
st.append((u, v, i))
print(-1)
sotanishy