結果

問題 No.1647 Travel in Mitaru city 2
ユーザー rlangevinrlangevin
提出日時 2023-12-11 12:45:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,159 bytes
コンパイル時間 195 ms
コンパイル使用メモリ 12,032 KB
実行使用メモリ 105,112 KB
最終ジャッジ日時 2023-12-11 12:46:17
合計ジャッジ時間 40,416 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
9,984 KB
testcase_01 AC 28 ms
9,984 KB
testcase_02 AC 27 ms
9,984 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 28 ms
10,112 KB
testcase_06 AC 28 ms
10,112 KB
testcase_07 WA -
testcase_08 AC 1,006 ms
97,292 KB
testcase_09 AC 906 ms
90,384 KB
testcase_10 AC 949 ms
97,616 KB
testcase_11 AC 649 ms
81,892 KB
testcase_12 AC 684 ms
80,852 KB
testcase_13 AC 659 ms
84,112 KB
testcase_14 AC 1,022 ms
100,232 KB
testcase_15 AC 972 ms
98,592 KB
testcase_16 AC 952 ms
94,068 KB
testcase_17 AC 668 ms
84,440 KB
testcase_18 AC 654 ms
83,964 KB
testcase_19 AC 843 ms
99,588 KB
testcase_20 AC 850 ms
93,952 KB
testcase_21 AC 945 ms
101,376 KB
testcase_22 AC 1,007 ms
101,244 KB
testcase_23 AC 1,011 ms
101,888 KB
testcase_24 AC 868 ms
94,852 KB
testcase_25 AC 921 ms
97,664 KB
testcase_26 AC 1,020 ms
101,888 KB
testcase_27 AC 1,022 ms
102,532 KB
testcase_28 AC 1,027 ms
105,112 KB
testcase_29 AC 1,036 ms
105,108 KB
testcase_30 AC 984 ms
99,476 KB
testcase_31 AC 1,012 ms
105,108 KB
testcase_32 AC 963 ms
103,572 KB
testcase_33 AC 904 ms
96,276 KB
testcase_34 AC 1,043 ms
105,112 KB
testcase_35 AC 940 ms
96,916 KB
testcase_36 AC 1,033 ms
105,112 KB
testcase_37 AC 976 ms
105,112 KB
testcase_38 AC 813 ms
91,076 KB
testcase_39 AC 700 ms
84,920 KB
testcase_40 AC 786 ms
90,304 KB
testcase_41 AC 745 ms
85,564 KB
testcase_42 AC 821 ms
90,688 KB
testcase_43 AC 28 ms
10,240 KB
testcase_44 AC 103 ms
27,392 KB
testcase_45 AC 492 ms
73,052 KB
testcase_46 AC 649 ms
73,040 KB
testcase_47 AC 497 ms
73,052 KB
testcase_48 AC 568 ms
73,052 KB
testcase_49 WA -
testcase_50 WA -
権限があれば一括ダウンロードができます

ソースコード

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