結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
9,984 KB
testcase_01 AC 29 ms
9,984 KB
testcase_02 AC 27 ms
9,984 KB
testcase_03 AC 29 ms
10,112 KB
testcase_04 WA -
testcase_05 AC 28 ms
10,112 KB
testcase_06 AC 30 ms
10,240 KB
testcase_07 AC 39 ms
11,392 KB
testcase_08 AC 966 ms
97,296 KB
testcase_09 AC 830 ms
90,388 KB
testcase_10 AC 914 ms
97,620 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 868 ms
94,984 KB
testcase_14 AC 949 ms
100,236 KB
testcase_15 AC 934 ms
98,596 KB
testcase_16 AC 914 ms
94,072 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 942 ms
101,248 KB
testcase_23 AC 959 ms
101,892 KB
testcase_24 AC 858 ms
88,152 KB
testcase_25 AC 735 ms
89,348 KB
testcase_26 AC 953 ms
101,892 KB
testcase_27 AC 973 ms
102,536 KB
testcase_28 AC 1,034 ms
105,116 KB
testcase_29 AC 1,013 ms
105,112 KB
testcase_30 AC 747 ms
90,776 KB
testcase_31 AC 958 ms
105,112 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 985 ms
105,116 KB
testcase_35 AC 903 ms
96,920 KB
testcase_36 AC 979 ms
105,116 KB
testcase_37 AC 1,014 ms
105,116 KB
testcase_38 AC 812 ms
91,080 KB
testcase_39 AC 726 ms
82,352 KB
testcase_40 AC 771 ms
90,308 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 30 ms
10,240 KB
testcase_44 AC 101 ms
27,392 KB
testcase_45 WA -
testcase_46 AC 652 ms
73,044 KB
testcase_47 WA -
testcase_48 WA -
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
    if i == 0:
        s, g = x, y + H
    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] == 0:
                ans = []
                now = u
                while temp:
                    ans.append(D[(now, temp[-1])])
                    now = temp.pop()
                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
    dfs(i, -1)

print(-1)
0