結果

問題 No.1647 Travel in Mitaru city 2
ユーザー ygd.ygd.
提出日時 2021-08-14 14:58:54
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,221 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 82,372 KB
実行使用メモリ 430,196 KB
最終ジャッジ日時 2024-04-15 12:52:11
合計ジャッジ時間 36,800 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
60,648 KB
testcase_01 AC 40 ms
52,456 KB
testcase_02 AC 40 ms
53,004 KB
testcase_03 AC 44 ms
55,152 KB
testcase_04 AC 94 ms
76,844 KB
testcase_05 AC 45 ms
53,932 KB
testcase_06 AC 48 ms
54,988 KB
testcase_07 AC 77 ms
72,864 KB
testcase_08 AC 546 ms
195,660 KB
testcase_09 AC 489 ms
176,500 KB
testcase_10 AC 546 ms
196,792 KB
testcase_11 AC 1,823 ms
338,372 KB
testcase_12 TLE -
testcase_13 AC 538 ms
190,040 KB
testcase_14 AC 635 ms
202,040 KB
testcase_15 AC 551 ms
199,496 KB
testcase_16 AC 525 ms
188,064 KB
testcase_17 AC 555 ms
180,328 KB
testcase_18 AC 603 ms
190,608 KB
testcase_19 AC 613 ms
197,728 KB
testcase_20 AC 2,358 ms
393,928 KB
testcase_21 AC 638 ms
191,456 KB
testcase_22 AC 668 ms
208,596 KB
testcase_23 AC 572 ms
205,340 KB
testcase_24 AC 680 ms
198,732 KB
testcase_25 AC 564 ms
175,540 KB
testcase_26 AC 569 ms
206,296 KB
testcase_27 AC 573 ms
205,516 KB
testcase_28 AC 577 ms
209,600 KB
testcase_29 AC 574 ms
211,300 KB
testcase_30 AC 578 ms
180,248 KB
testcase_31 AC 592 ms
210,576 KB
testcase_32 AC 667 ms
196,608 KB
testcase_33 AC 709 ms
180,720 KB
testcase_34 AC 578 ms
210,180 KB
testcase_35 AC 505 ms
187,808 KB
testcase_36 AC 578 ms
210,984 KB
testcase_37 AC 575 ms
210,496 KB
testcase_38 AC 702 ms
210,920 KB
testcase_39 AC 498 ms
143,188 KB
testcase_40 AC 496 ms
165,536 KB
testcase_41 AC 2,122 ms
309,696 KB
testcase_42 AC 2,366 ms
331,928 KB
testcase_43 AC 62 ms
75,540 KB
testcase_44 AC 46 ms
66,368 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