結果

問題 No.1647 Travel in Mitaru city 2
ユーザー ygd.ygd.
提出日時 2021-08-14 14:59:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,221 bytes
コンパイル時間 350 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 86,108 KB
最終ジャッジ日時 2024-04-15 12:54:21
合計ジャッジ時間 45,726 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
17,952 KB
testcase_01 AC 32 ms
10,880 KB
testcase_02 AC 33 ms
10,880 KB
testcase_03 AC 32 ms
10,880 KB
testcase_04 AC 89 ms
11,264 KB
testcase_05 AC 32 ms
11,008 KB
testcase_06 AC 33 ms
10,880 KB
testcase_07 AC 48 ms
11,776 KB
testcase_08 AC 1,014 ms
79,184 KB
testcase_09 AC 910 ms
72,920 KB
testcase_10 AC 998 ms
79,128 KB
testcase_11 AC 1,368 ms
73,496 KB
testcase_12 AC 1,371 ms
70,380 KB
testcase_13 AC 993 ms
76,616 KB
testcase_14 AC 1,042 ms
80,972 KB
testcase_15 AC 1,021 ms
80,096 KB
testcase_16 AC 951 ms
76,472 KB
testcase_17 AC 936 ms
73,492 KB
testcase_18 AC 1,024 ms
78,652 KB
testcase_19 AC 1,038 ms
78,664 KB
testcase_20 AC 1,429 ms
69,188 KB
testcase_21 AC 1,044 ms
74,236 KB
testcase_22 AC 1,061 ms
82,492 KB
testcase_23 AC 1,050 ms
82,884 KB
testcase_24 AC 948 ms
69,472 KB
testcase_25 AC 880 ms
71,112 KB
testcase_26 AC 1,055 ms
82,884 KB
testcase_27 AC 1,070 ms
83,528 KB
testcase_28 AC 1,079 ms
85,468 KB
testcase_29 AC 1,089 ms
86,100 KB
testcase_30 AC 866 ms
71,640 KB
testcase_31 AC 1,098 ms
85,464 KB
testcase_32 AC 1,088 ms
74,712 KB
testcase_33 AC 1,044 ms
69,336 KB
testcase_34 AC 1,059 ms
85,332 KB
testcase_35 AC 972 ms
78,040 KB
testcase_36 AC 1,081 ms
86,108 KB
testcase_37 AC 1,077 ms
85,340 KB
testcase_38 AC 941 ms
72,200 KB
testcase_39 AC 865 ms
63,604 KB
testcase_40 AC 940 ms
71,428 KB
testcase_41 AC 1,369 ms
66,208 KB
testcase_42 AC 1,891 ms
73,208 KB
testcase_43 AC 44 ms
11,008 KB
testcase_44 AC 117 ms
26,624 KB
testcase_45 TLE -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(1000000)

def main():
    H,W,N = map(int,input().split())
    dic = {}
    G = [[] for _ in range(H+W)]
    for i in range(N):
        x,y = map(int,input().split())
        x -= 1; y -= 1
        dic[(x,y+H)] = i+1 #1-index
        h = x
        w = y + H
        G[h].append(w)
        G[w].append(h)
    #print(G)
    #print(dic)
    def ans_print(X):
        #print("X",X)
        ret = []
        for i in range(len(X)):
            if i == len(X) - 1: #最後
                a = X[i]; b = X[0]
            else:
                a = X[i]; b = X[i+1]
            if a > b:
                a,b = b,a
            ret.append(dic[(a,b)])
        print(len(ret))
        print(*ret)
        exit()

    def dfs(v):
        stack.append(v)
        visited[v] = 1
        for u in G[v]:
            if u == stack[0] and len(stack) > 2:
                ans_print(stack)
            if visited[u] == 1: continue
            #stack.append(u)
            dfs(u)
            stack.pop()
            visited[u] = 0

    for i in range(H+W):
        stack = []
        visited = [0]*(H+W)
        dfs(i)
        #print("NEXT",stack)
    print(-1)
        



if __name__ == '__main__':
    main()
0