結果

問題 No.1647 Travel in Mitaru city 2
ユーザー sotanishysotanishy
提出日時 2021-08-15 00:28:13
言語 PyPy3
(7.3.15)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,042 bytes
コンパイル時間 215 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 135,296 KB
最終ジャッジ日時 2024-04-21 05:02:09
合計ジャッジ時間 20,009 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
51,968 KB
testcase_01 AC 42 ms
52,096 KB
testcase_02 AC 39 ms
51,968 KB
testcase_03 AC 41 ms
52,992 KB
testcase_04 AC 55 ms
64,000 KB
testcase_05 AC 40 ms
52,480 KB
testcase_06 AC 40 ms
53,248 KB
testcase_07 AC 55 ms
64,896 KB
testcase_08 AC 379 ms
129,408 KB
testcase_09 AC 378 ms
122,880 KB
testcase_10 AC 391 ms
129,920 KB
testcase_11 AC 368 ms
125,952 KB
testcase_12 AC 379 ms
120,064 KB
testcase_13 AC 384 ms
128,000 KB
testcase_14 AC 409 ms
132,096 KB
testcase_15 AC 396 ms
131,968 KB
testcase_16 AC 384 ms
128,000 KB
testcase_17 AC 376 ms
125,952 KB
testcase_18 AC 426 ms
130,816 KB
testcase_19 AC 396 ms
129,792 KB
testcase_20 AC 389 ms
120,064 KB
testcase_21 AC 381 ms
126,592 KB
testcase_22 AC 390 ms
132,736 KB
testcase_23 AC 409 ms
134,144 KB
testcase_24 AC 379 ms
124,544 KB
testcase_25 AC 381 ms
120,064 KB
testcase_26 AC 396 ms
133,888 KB
testcase_27 AC 403 ms
134,784 KB
testcase_28 AC 374 ms
134,912 KB
testcase_29 AC 388 ms
135,296 KB
testcase_30 AC 298 ms
117,248 KB
testcase_31 AC 384 ms
135,168 KB
testcase_32 AC 388 ms
126,976 KB
testcase_33 AC 366 ms
123,392 KB
testcase_34 AC 414 ms
134,912 KB
testcase_35 AC 385 ms
129,664 KB
testcase_36 AC 397 ms
135,040 KB
testcase_37 AC 405 ms
135,040 KB
testcase_38 AC 421 ms
126,960 KB
testcase_39 AC 384 ms
121,728 KB
testcase_40 AC 374 ms
126,080 KB
testcase_41 AC 364 ms
119,552 KB
testcase_42 AC 376 ms
126,976 KB
testcase_43 AC 48 ms
60,032 KB
testcase_44 AC 54 ms
67,840 KB
testcase_45 AC 365 ms
124,928 KB
testcase_46 AC 387 ms
127,488 KB
testcase_47 AC 390 ms
127,488 KB
testcase_48 AC 408 ms
127,360 KB
testcase_49 AC 377 ms
125,056 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 u == s:
                ans = [i]
                while v != s:
                    v, i = prev[v]
                    ans.append(i)
                print(len(ans))
                print(*map(lambda x: x + 1, ans[::-1]))
                exit()
            if prev[u] is None:
                st.append((u, v, i))
print(-1)
0