結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
17,824 KB
testcase_01 AC 31 ms
10,752 KB
testcase_02 AC 30 ms
10,752 KB
testcase_03 AC 31 ms
10,880 KB
testcase_04 AC 81 ms
11,264 KB
testcase_05 AC 32 ms
10,752 KB
testcase_06 AC 33 ms
10,752 KB
testcase_07 AC 38 ms
11,648 KB
testcase_08 AC 777 ms
81,232 KB
testcase_09 AC 688 ms
74,964 KB
testcase_10 AC 778 ms
81,168 KB
testcase_11 AC 1,109 ms
75,512 KB
testcase_12 AC 1,092 ms
72,404 KB
testcase_13 AC 749 ms
78,540 KB
testcase_14 AC 789 ms
83,016 KB
testcase_15 AC 781 ms
82,028 KB
testcase_16 AC 741 ms
78,392 KB
testcase_17 AC 733 ms
75,412 KB
testcase_18 AC 784 ms
80,692 KB
testcase_19 AC 807 ms
80,584 KB
testcase_20 AC 1,158 ms
71,264 KB
testcase_21 AC 803 ms
76,204 KB
testcase_22 AC 811 ms
84,412 KB
testcase_23 AC 829 ms
84,804 KB
testcase_24 AC 709 ms
71,456 KB
testcase_25 AC 652 ms
73,024 KB
testcase_26 AC 816 ms
84,932 KB
testcase_27 AC 814 ms
85,572 KB
testcase_28 AC 847 ms
87,256 KB
testcase_29 AC 839 ms
88,148 KB
testcase_30 AC 644 ms
73,432 KB
testcase_31 AC 843 ms
87,384 KB
testcase_32 AC 848 ms
76,760 KB
testcase_33 AC 833 ms
71,380 KB
testcase_34 AC 841 ms
87,256 KB
testcase_35 AC 746 ms
79,956 KB
testcase_36 AC 839 ms
88,032 KB
testcase_37 AC 841 ms
87,256 KB
testcase_38 AC 698 ms
74,244 KB
testcase_39 AC 624 ms
65,648 KB
testcase_40 AC 687 ms
73,476 KB
testcase_41 AC 1,094 ms
68,108 KB
testcase_42 AC 1,591 ms
75,292 KB
testcase_43 AC 41 ms
11,008 KB
testcase_44 AC 114 ms
26,624 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 = {}
    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 range(H):
        stack = []
        visited = [0]*(H+W)
        dfs(i)
        #print("NEXT",stack)
    print(-1)
        
if __name__ == '__main__':
    main()
0