結果

問題 No.1647 Travel in Mitaru city 2
ユーザー sotanishysotanishy
提出日時 2021-08-15 00:26:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,019 bytes
コンパイル時間 510 ms
コンパイル使用メモリ 82,396 KB
実行使用メモリ 135,552 KB
最終ジャッジ日時 2024-04-15 22:23:23
合計ジャッジ時間 28,158 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,352 KB
testcase_01 AC 43 ms
52,224 KB
testcase_02 AC 44 ms
52,736 KB
testcase_03 AC 45 ms
52,864 KB
testcase_04 AC 58 ms
64,512 KB
testcase_05 AC 44 ms
53,248 KB
testcase_06 AC 47 ms
53,504 KB
testcase_07 AC 59 ms
65,024 KB
testcase_08 AC 485 ms
129,792 KB
testcase_09 WA -
testcase_10 AC 482 ms
129,940 KB
testcase_11 AC 453 ms
125,900 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 536 ms
132,284 KB
testcase_15 AC 500 ms
132,096 KB
testcase_16 AC 470 ms
127,720 KB
testcase_17 AC 450 ms
126,592 KB
testcase_18 WA -
testcase_19 AC 473 ms
129,920 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 508 ms
133,132 KB
testcase_23 AC 509 ms
134,304 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 506 ms
134,144 KB
testcase_27 AC 515 ms
134,912 KB
testcase_28 AC 507 ms
135,212 KB
testcase_29 AC 500 ms
135,168 KB
testcase_30 AC 375 ms
117,376 KB
testcase_31 AC 508 ms
135,552 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 511 ms
135,284 KB
testcase_35 WA -
testcase_36 AC 537 ms
135,360 KB
testcase_37 AC 533 ms
135,464 KB
testcase_38 AC 510 ms
127,272 KB
testcase_39 WA -
testcase_40 AC 513 ms
126,080 KB
testcase_41 WA -
testcase_42 AC 484 ms
126,984 KB
testcase_43 AC 51 ms
60,416 KB
testcase_44 AC 55 ms
68,096 KB
testcase_45 AC 447 ms
125,312 KB
testcase_46 AC 490 ms
127,488 KB
testcase_47 AC 483 ms
128,076 KB
testcase_48 AC 485 ms
127,296 KB
testcase_49 AC 447 ms
125,428 KB
testcase_50 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

H, W, N = map(int, input().split())
G = [set() for _ in range(H+W)]
for i in range(N):
    x, y = map(lambda x: int(x) - 1, input().split())
    G[x].add((H+y, i))
    G[H+y].add((x, i))
st = []
for v in range(H+W):
    if len(G[v]) == 1:
        st.append(v)
while st:
    v = st.pop()
    for u, i in G[v]:
        G[u].remove((v, i))
        if len(G[u]) == 1:
            st.append(u)
    G[v] = set()
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