結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
17,696 KB
testcase_01 AC 32 ms
10,752 KB
testcase_02 AC 36 ms
10,752 KB
testcase_03 AC 33 ms
10,752 KB
testcase_04 AC 85 ms
11,264 KB
testcase_05 AC 32 ms
10,752 KB
testcase_06 AC 32 ms
10,752 KB
testcase_07 AC 39 ms
11,520 KB
testcase_08 AC 811 ms
79,064 KB
testcase_09 AC 711 ms
72,920 KB
testcase_10 AC 807 ms
79,124 KB
testcase_11 AC 1,172 ms
73,500 KB
testcase_12 AC 1,167 ms
70,536 KB
testcase_13 AC 778 ms
76,500 KB
testcase_14 AC 817 ms
80,848 KB
testcase_15 AC 813 ms
79,972 KB
testcase_16 AC 770 ms
76,344 KB
testcase_17 AC 768 ms
73,372 KB
testcase_18 AC 833 ms
78,652 KB
testcase_19 AC 839 ms
78,536 KB
testcase_20 AC 1,186 ms
69,064 KB
testcase_21 AC 802 ms
74,120 KB
testcase_22 AC 837 ms
82,384 KB
testcase_23 AC 844 ms
82,760 KB
testcase_24 AC 723 ms
69,320 KB
testcase_25 AC 652 ms
71,112 KB
testcase_26 AC 826 ms
82,892 KB
testcase_27 AC 845 ms
83,656 KB
testcase_28 AC 862 ms
85,212 KB
testcase_29 AC 867 ms
86,104 KB
testcase_30 AC 664 ms
71,388 KB
testcase_31 AC 872 ms
85,208 KB
testcase_32 AC 870 ms
74,588 KB
testcase_33 AC 839 ms
69,336 KB
testcase_34 AC 863 ms
85,212 KB
testcase_35 AC 774 ms
77,916 KB
testcase_36 AC 880 ms
85,980 KB
testcase_37 AC 870 ms
85,216 KB
testcase_38 AC 722 ms
72,208 KB
testcase_39 AC 643 ms
63,596 KB
testcase_40 AC 703 ms
71,424 KB
testcase_41 AC 1,143 ms
66,212 KB
testcase_42 AC 1,665 ms
73,216 KB
testcase_43 AC 44 ms
11,008 KB
testcase_44 AC 118 ms
26,496 KB
testcase_45 TLE -
testcase_46 -- -
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 = {}
    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