結果

問題 No.1647 Travel in Mitaru city 2
ユーザー rlangevinrlangevin
提出日時 2023-12-11 12:45:32
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 1,159 bytes
コンパイル時間 379 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 105,768 KB
最終ジャッジ日時 2024-09-27 04:28:45
合計ジャッジ時間 39,621 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import *

H, W, N = map(int, input().split())
G = [[] for i in range(H + W)]
D = dict()
for i in range(N):
    x, y = map(int, input().split())
    x, y = x - 1, y - 1
    G[x].append(y + H)
    G[y + H].append(x)
    D[(x, y+H)] = i + 1
    D[(y+H, x)] = i + 1

seen = [0] * (H + W)
seen2 = [0] * (H + W)
temp = []

def dfs(s, p):
    for u in G[s]:
        if u == p:
            continue
        if seen[u]:
            if seen2[u]:
                ans = []
                now = u
                while temp[-1] != u:
                    ans.append(D[(now, temp[-1])])
                    now = temp.pop()
                ans.append(D[(now, u)])
                ans.reverse()
                print(len(ans))
                print(*ans)
                exit()
            continue
            
        seen[u] = 1
        seen2[u] = 1
        temp.append(u)
        dfs(u, s)
        seen2[u] = 0
        temp.pop()
    return 


for i in range(H):
    if seen[i]:
        continue
    temp = [i]
    seen[i] = 1
    seen2[i] = 1
    dfs(i, -1)
    seen2[i] = 0

print(-1)
0