結果

問題 No.1647 Travel in Mitaru city 2
ユーザー ProgrammerryokiProgrammerryoki
提出日時 2021-08-13 22:12:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,521 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 25,500 KB
最終ジャッジ日時 2024-04-14 18:14:52
合計ジャッジ時間 7,808 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
17,692 KB
testcase_01 AC 30 ms
10,880 KB
testcase_02 AC 31 ms
10,880 KB
testcase_03 AC 41 ms
10,880 KB
testcase_04 AC 706 ms
11,520 KB
testcase_05 AC 37 ms
10,880 KB
testcase_06 AC 48 ms
11,136 KB
testcase_07 AC 1,518 ms
11,648 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin, setrecursionlimit
setrecursionlimit(10**6)

input = stdin.readline
H,W,N = [int(i) for i in input().split()]
odd = {}
even = {}
points = []
for ind in range(N):
    x,y = [int(i) for i in input().split()]
    points.append((x,y))
    even.setdefault(x, {})
    odd.setdefault(y, {})
    for i,j in points:
        if i == x:
            even[i].setdefault(x, set())
            even[x].setdefault(i, set())
            even[i][x].add(ind+1)
            even[x][i].add(ind+1)
        if j == y:
            odd[j].setdefault(y, set())
            odd[y].setdefault(j, set())
            odd[j][y].add(ind+1)
            odd[y][j].add(ind+1)
#
# print(odd)
# print(even)

order = []
seen = set()
start = 0
def dfs(x,y):
    global order, seen
    rodd = len(order)&1
    graph = odd if rodd else even
    nxt = y if rodd else x
    # print(x,y,rodd,order,seen)
    for lst in graph[nxt]:
        gnl = graph[nxt][lst]
        for n in gnl:
            if n not in seen:
                seen.add(n)
                order.append(n)
                i,j = points[n-1]
                dfs(i,j)
                order.pop()
                seen.remove(n)
            else:
                if n == start and len(order) >= 4:
                    # print(order)
                    raise ConnectionError


try:
    start = 1
    order.append(1)
    seen.add(1)
    dfs(points[0][0], points[0][1])
    print(-1)
except ConnectionError:
    print(len(order))
    print(" ".join(str(i) for i in order))
    exit()
0