結果

問題 No.1647 Travel in Mitaru city 2
ユーザー ygd.ygd.
提出日時 2021-08-14 15:06:19
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,288 bytes
コンパイル時間 232 ms
コンパイル使用メモリ 82,420 KB
実行使用メモリ 351,788 KB
最終ジャッジ日時 2024-04-15 13:02:25
合計ジャッジ時間 32,044 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
59,552 KB
testcase_01 AC 44 ms
52,884 KB
testcase_02 AC 42 ms
53,228 KB
testcase_03 AC 46 ms
53,960 KB
testcase_04 AC 54 ms
62,280 KB
testcase_05 AC 43 ms
52,472 KB
testcase_06 AC 44 ms
52,996 KB
testcase_07 AC 55 ms
63,012 KB
testcase_08 AC 599 ms
195,368 KB
testcase_09 AC 513 ms
177,012 KB
testcase_10 AC 659 ms
198,020 KB
testcase_11 AC 568 ms
172,096 KB
testcase_12 AC 582 ms
169,532 KB
testcase_13 AC 1,554 ms
351,788 KB
testcase_14 AC 662 ms
202,592 KB
testcase_15 AC 573 ms
199,488 KB
testcase_16 AC 552 ms
187,208 KB
testcase_17 AC 564 ms
183,572 KB
testcase_18 AC 636 ms
189,348 KB
testcase_19 AC 630 ms
190,704 KB
testcase_20 AC 680 ms
189,000 KB
testcase_21 AC 749 ms
190,280 KB
testcase_22 AC 608 ms
202,072 KB
testcase_23 AC 576 ms
204,912 KB
testcase_24 AC 602 ms
167,404 KB
testcase_25 AC 633 ms
178,156 KB
testcase_26 AC 605 ms
205,104 KB
testcase_27 AC 589 ms
207,388 KB
testcase_28 AC 606 ms
213,244 KB
testcase_29 AC 603 ms
212,856 KB
testcase_30 AC 534 ms
189,524 KB
testcase_31 AC 603 ms
212,540 KB
testcase_32 AC 469 ms
171,704 KB
testcase_33 AC 599 ms
174,124 KB
testcase_34 AC 616 ms
213,460 KB
testcase_35 AC 534 ms
188,328 KB
testcase_36 AC 634 ms
212,568 KB
testcase_37 AC 649 ms
213,040 KB
testcase_38 AC 840 ms
261,508 KB
testcase_39 AC 610 ms
150,928 KB
testcase_40 AC 799 ms
250,596 KB
testcase_41 AC 527 ms
143,984 KB
testcase_42 AC 530 ms
167,652 KB
testcase_43 AC 46 ms
57,416 KB
testcase_44 AC 53 ms
65,976 KB
testcase_45 AC 1,844 ms
284,000 KB
testcase_46 TLE -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.buffer.readline

def main():
    H,W,N = map(int,input().split())
    dic = {}
    Start = set([])
    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)
        Start.add(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 Start:
        stack = []
        visited = [0]*(H+W)
        dfs(i)
        #print("NEXT",stack)
    print(-1)
        
if __name__ == '__main__':
    main()
0