結果

問題 No.1647 Travel in Mitaru city 2
ユーザー nephrologistnephrologist
提出日時 2021-08-14 16:09:42
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,555 bytes
コンパイル時間 193 ms
コンパイル使用メモリ 82,332 KB
実行使用メモリ 297,860 KB
最終ジャッジ日時 2024-04-15 14:11:15
合計ジャッジ時間 26,874 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
80,240 KB
testcase_01 AC 63 ms
80,384 KB
testcase_02 AC 57 ms
73,216 KB
testcase_03 AC 55 ms
74,836 KB
testcase_04 WA -
testcase_05 AC 56 ms
73,520 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 467 ms
150,144 KB
testcase_09 WA -
testcase_10 AC 478 ms
150,240 KB
testcase_11 AC 424 ms
145,040 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 488 ms
150,192 KB
testcase_15 AC 481 ms
150,052 KB
testcase_16 AC 446 ms
147,440 KB
testcase_17 AC 455 ms
151,584 KB
testcase_18 WA -
testcase_19 AC 482 ms
149,844 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 503 ms
149,452 KB
testcase_23 AC 499 ms
149,048 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 485 ms
149,476 KB
testcase_27 AC 491 ms
149,464 KB
testcase_28 AC 497 ms
151,212 KB
testcase_29 AC 493 ms
150,864 KB
testcase_30 WA -
testcase_31 AC 495 ms
151,288 KB
testcase_32 AC 433 ms
151,508 KB
testcase_33 WA -
testcase_34 AC 498 ms
151,072 KB
testcase_35 WA -
testcase_36 AC 485 ms
151,328 KB
testcase_37 AC 480 ms
151,504 KB
testcase_38 AC 460 ms
145,704 KB
testcase_39 WA -
testcase_40 AC 456 ms
145,748 KB
testcase_41 WA -
testcase_42 AC 452 ms
145,708 KB
testcase_43 AC 73 ms
94,284 KB
testcase_44 AC 55 ms
73,296 KB
testcase_45 WA -
testcase_46 TLE -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

input = sys.stdin.buffer.readline
h, w, n = map(int, input().split())
num = 10 ** 5
graph = [[] for _ in range(2 * num)]
start = set()
edges = {}
e = {}
for i in range(n):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    b += num
    graph[a].append(b)
    graph[b].append(a)
    start.add(a)
    edges[(a, b)] = i
    edges[(b, a)] = i
    e[i] = (a, b)


used = [0] * num * 2


# graph and n is necessary
def dfs(start):
    par = [-1] * num * 2
    depth = [-1] * num * 2
    size = [0] * num * 2
    stack = []
    stack.append(~start)
    stack.append(start)
    euler = []
    while stack:
        v = stack.pop()
        if v >= 0:
            d = depth[v]
            used[v] = 1
            euler.append(v)
            for u in graph[v]:
                if par[v] == u:
                    continue
                if used[u]:
                    euler.append(u)
                    return 1, euler
                par[u] = v
                stack.append(~u)
                stack.append(u)
        else:
            a = ~v
            euler.pop()

    return 0, []


for s in start:
    if used[s]:
        continue
    flag, euler = dfs(s)
    if flag:
        ans = []
        for u, v in zip(euler, euler[1:]):
            ans.append(edges[(u, v)] + 1)
        if len(ans) >= 4:
            a, b = ans[0], ans[1]
            x1, y1 = e[a - 1]
            x2, y2 = e[b - 1]
            if y1 == y2:
                ans = ans[::-1]
            print(len(ans))
            print(*ans)
            exit()


print(-1)

0