結果

問題 No.1647 Travel in Mitaru city 2
ユーザー sotanishysotanishy
提出日時 2021-08-15 00:18:20
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 803 bytes
コンパイル時間 213 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 117,504 KB
最終ジャッジ日時 2024-04-15 22:14:13
合計ジャッジ時間 19,340 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
51,968 KB
testcase_01 AC 44 ms
52,096 KB
testcase_02 AC 41 ms
51,712 KB
testcase_03 AC 41 ms
52,480 KB
testcase_04 AC 53 ms
62,976 KB
testcase_05 AC 42 ms
52,480 KB
testcase_06 AC 42 ms
52,992 KB
testcase_07 AC 56 ms
64,256 KB
testcase_08 AC 296 ms
113,024 KB
testcase_09 WA -
testcase_10 AC 296 ms
112,768 KB
testcase_11 AC 274 ms
109,696 KB
testcase_12 AC 297 ms
104,764 KB
testcase_13 WA -
testcase_14 AC 312 ms
114,816 KB
testcase_15 AC 318 ms
114,432 KB
testcase_16 AC 282 ms
111,360 KB
testcase_17 AC 288 ms
109,312 KB
testcase_18 WA -
testcase_19 AC 292 ms
111,744 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 324 ms
115,456 KB
testcase_23 AC 316 ms
116,224 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 317 ms
116,352 KB
testcase_27 AC 317 ms
117,120 KB
testcase_28 AC 321 ms
117,120 KB
testcase_29 AC 323 ms
117,120 KB
testcase_30 AC 240 ms
100,352 KB
testcase_31 AC 327 ms
117,120 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 338 ms
117,376 KB
testcase_35 WA -
testcase_36 AC 327 ms
117,120 KB
testcase_37 AC 336 ms
117,504 KB
testcase_38 AC 303 ms
109,440 KB
testcase_39 WA -
testcase_40 AC 300 ms
108,672 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 49 ms
59,392 KB
testcase_44 AC 54 ms
64,896 KB
testcase_45 WA -
testcase_46 AC 300 ms
100,864 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 204 ms
97,792 KB
testcase_50 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0