結果

問題 No.1647 Travel in Mitaru city 2
ユーザー ygd.ygd.
提出日時 2021-08-14 15:01:10
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,221 bytes
コンパイル時間 441 ms
コンパイル使用メモリ 82,336 KB
実行使用メモリ 431,092 KB
最終ジャッジ日時 2024-04-15 12:56:14
合計ジャッジ時間 43,360 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
57,856 KB
testcase_01 AC 44 ms
52,480 KB
testcase_02 AC 46 ms
52,224 KB
testcase_03 AC 47 ms
53,632 KB
testcase_04 AC 105 ms
76,812 KB
testcase_05 AC 48 ms
53,504 KB
testcase_06 AC 49 ms
54,016 KB
testcase_07 AC 77 ms
71,552 KB
testcase_08 AC 639 ms
195,132 KB
testcase_09 AC 569 ms
176,224 KB
testcase_10 AC 652 ms
196,948 KB
testcase_11 AC 2,147 ms
337,124 KB
testcase_12 TLE -
testcase_13 AC 651 ms
189,168 KB
testcase_14 AC 768 ms
201,616 KB
testcase_15 AC 657 ms
198,536 KB
testcase_16 AC 602 ms
186,372 KB
testcase_17 AC 671 ms
179,380 KB
testcase_18 AC 725 ms
189,964 KB
testcase_19 AC 734 ms
196,888 KB
testcase_20 TLE -
testcase_21 AC 740 ms
190,488 KB
testcase_22 AC 765 ms
207,628 KB
testcase_23 AC 689 ms
203,416 KB
testcase_24 AC 777 ms
198,680 KB
testcase_25 AC 678 ms
174,352 KB
testcase_26 AC 654 ms
204,952 KB
testcase_27 AC 689 ms
205,040 KB
testcase_28 AC 679 ms
209,612 KB
testcase_29 AC 684 ms
209,980 KB
testcase_30 AC 706 ms
179,392 KB
testcase_31 AC 659 ms
210,248 KB
testcase_32 AC 765 ms
196,668 KB
testcase_33 AC 823 ms
180,160 KB
testcase_34 AC 687 ms
210,372 KB
testcase_35 AC 588 ms
187,140 KB
testcase_36 AC 692 ms
209,996 KB
testcase_37 AC 694 ms
210,116 KB
testcase_38 AC 824 ms
210,260 KB
testcase_39 AC 607 ms
142,836 KB
testcase_40 AC 594 ms
164,608 KB
testcase_41 TLE -
testcase_42 TLE -
testcase_43 AC 75 ms
75,512 KB
testcase_44 AC 62 ms
65,152 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