結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
80,108 KB
testcase_01 AC 60 ms
80,900 KB
testcase_02 AC 55 ms
74,188 KB
testcase_03 AC 58 ms
73,520 KB
testcase_04 WA -
testcase_05 AC 61 ms
73,676 KB
testcase_06 WA -
testcase_07 AC 65 ms
83,336 KB
testcase_08 AC 467 ms
150,140 KB
testcase_09 WA -
testcase_10 AC 461 ms
150,136 KB
testcase_11 AC 413 ms
145,032 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 487 ms
150,096 KB
testcase_15 AC 474 ms
149,864 KB
testcase_16 AC 449 ms
146,964 KB
testcase_17 AC 430 ms
151,580 KB
testcase_18 WA -
testcase_19 AC 479 ms
149,972 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 511 ms
149,064 KB
testcase_23 AC 505 ms
148,856 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 487 ms
149,296 KB
testcase_27 AC 486 ms
149,268 KB
testcase_28 AC 490 ms
151,216 KB
testcase_29 AC 482 ms
150,728 KB
testcase_30 WA -
testcase_31 AC 489 ms
151,400 KB
testcase_32 AC 442 ms
151,280 KB
testcase_33 WA -
testcase_34 AC 509 ms
150,728 KB
testcase_35 WA -
testcase_36 AC 497 ms
151,204 KB
testcase_37 AC 497 ms
151,376 KB
testcase_38 AC 479 ms
145,672 KB
testcase_39 WA -
testcase_40 AC 452 ms
145,448 KB
testcase_41 WA -
testcase_42 AC 463 ms
145,584 KB
testcase_43 AC 73 ms
95,376 KB
testcase_44 AC 55 ms
73,540 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 x1 == x2:
                ans = ans[::-1]
            print(len(ans))
            print(*ans)
            exit()


print(-1)

0