結果

問題 No.1647 Travel in Mitaru city 2
ユーザー tktk_snsntktk_snsn
提出日時 2021-08-13 22:03:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 966 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 72,576 KB
最終ジャッジ日時 2024-04-14 18:01:30
合計ジャッジ時間 32,325 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,752 KB
testcase_01 AC 37 ms
10,752 KB
testcase_02 AC 33 ms
10,752 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 602 ms
59,520 KB
testcase_09 AC 510 ms
54,656 KB
testcase_10 AC 566 ms
59,392 KB
testcase_11 RE -
testcase_12 AC 453 ms
46,208 KB
testcase_13 RE -
testcase_14 AC 624 ms
60,672 KB
testcase_15 AC 618 ms
60,160 KB
testcase_16 AC 544 ms
57,600 KB
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 642 ms
61,952 KB
testcase_23 AC 666 ms
62,336 KB
testcase_24 AC 504 ms
52,224 KB
testcase_25 AC 551 ms
56,448 KB
testcase_26 AC 647 ms
62,464 KB
testcase_27 AC 650 ms
62,720 KB
testcase_28 AC 648 ms
64,256 KB
testcase_29 AC 645 ms
64,128 KB
testcase_30 WA -
testcase_31 AC 665 ms
64,128 KB
testcase_32 WA -
testcase_33 RE -
testcase_34 AC 668 ms
64,256 KB
testcase_35 AC 619 ms
58,752 KB
testcase_36 AC 664 ms
64,128 KB
testcase_37 AC 668 ms
64,256 KB
testcase_38 AC 568 ms
54,400 KB
testcase_39 RE -
testcase_40 AC 549 ms
53,888 KB
testcase_41 RE -
testcase_42 AC 545 ms
54,144 KB
testcase_43 AC 31 ms
10,880 KB
testcase_44 AC 114 ms
24,960 KB
testcase_45 RE -
testcase_46 TLE -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

H, W, N = map(int, input().split())
X = [-1] * N
Y = [-1] * N
row = [[] for _ in range(H+1)]
col = [[] for _ in range(W+1)]
for i in range(N):
    X[i], Y[i] = map(int, input().split())
    row[X[i]].append(i)
    col[Y[i]].append(i)

v0 = [0] * N
v1 = [0] * N

pos = [X, Y]
G = [row, col]
vis = [v0, v1]
tour = []


def dfs(s, F, p=-1):
    vis[F][s] = 1
    tour.append(s + 1)
    for t in G[F][pos[F][s]]:
        if t == p or t == s:
            continue
        if vis[1-F][t]:
            tour.append(t + 1)
            return True
        if dfs(t, 1-F, s):
            return True
    tour.pop()
    vis[F][s] = 0
    return False


for i in range(N):
    if vis[0][i]:
        continue
    tour = []
    if dfs(i, 0):
        tour.reverse()
        last = tour.pop()
        idx = tour.index(last)
        print(len(tour) - idx)
        print(*tour[idx:])
        exit()
print(-1)
0