結果

問題 No.1647 Travel in Mitaru city 2
ユーザー tktk_snsntktk_snsn
提出日時 2021-08-13 22:01:56
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 948 bytes
コンパイル時間 339 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 72,448 KB
最終ジャッジ日時 2024-04-14 17:57:09
合計ジャッジ時間 31,254 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,752 KB
testcase_01 AC 31 ms
10,752 KB
testcase_02 AC 30 ms
10,752 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 595 ms
59,392 KB
testcase_09 AC 505 ms
54,656 KB
testcase_10 AC 550 ms
59,392 KB
testcase_11 RE -
testcase_12 AC 464 ms
46,080 KB
testcase_13 RE -
testcase_14 AC 592 ms
60,800 KB
testcase_15 AC 573 ms
60,032 KB
testcase_16 AC 530 ms
57,600 KB
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 602 ms
61,952 KB
testcase_23 AC 604 ms
62,464 KB
testcase_24 AC 477 ms
52,352 KB
testcase_25 AC 513 ms
56,448 KB
testcase_26 AC 639 ms
62,464 KB
testcase_27 AC 610 ms
62,720 KB
testcase_28 AC 643 ms
64,256 KB
testcase_29 AC 618 ms
64,256 KB
testcase_30 WA -
testcase_31 AC 609 ms
64,256 KB
testcase_32 WA -
testcase_33 RE -
testcase_34 AC 623 ms
64,128 KB
testcase_35 AC 543 ms
58,752 KB
testcase_36 AC 619 ms
64,128 KB
testcase_37 AC 606 ms
64,256 KB
testcase_38 AC 514 ms
54,400 KB
testcase_39 RE -
testcase_40 AC 529 ms
54,016 KB
testcase_41 RE -
testcase_42 AC 547 ms
54,272 KB
testcase_43 AC 32 ms
11,008 KB
testcase_44 AC 107 ms
24,960 KB
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
権限があれば一括ダウンロードができます

ソースコード

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()
    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