結果

問題 No.1647 Travel in Mitaru city 2
ユーザー ansainansain
提出日時 2021-08-20 23:33:08
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,574 ms / 2,500 ms
コード長 2,401 bytes
コンパイル時間 115 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 111,416 KB
最終ジャッジ日時 2024-10-14 07:29:14
合計ジャッジ時間 47,755 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 29 ms
10,880 KB
testcase_02 AC 31 ms
11,008 KB
testcase_03 AC 33 ms
10,880 KB
testcase_04 AC 39 ms
11,904 KB
testcase_05 AC 31 ms
10,880 KB
testcase_06 AC 31 ms
10,880 KB
testcase_07 AC 41 ms
12,288 KB
testcase_08 AC 1,060 ms
101,668 KB
testcase_09 AC 971 ms
94,060 KB
testcase_10 AC 1,084 ms
102,288 KB
testcase_11 AC 848 ms
84,716 KB
testcase_12 AC 849 ms
83,968 KB
testcase_13 AC 875 ms
87,936 KB
testcase_14 AC 1,072 ms
104,680 KB
testcase_15 AC 1,066 ms
103,464 KB
testcase_16 AC 1,015 ms
97,972 KB
testcase_17 AC 881 ms
87,936 KB
testcase_18 AC 890 ms
87,756 KB
testcase_19 AC 1,013 ms
105,156 KB
testcase_20 AC 979 ms
98,860 KB
testcase_21 AC 1,037 ms
107,016 KB
testcase_22 AC 1,081 ms
106,576 KB
testcase_23 AC 1,091 ms
107,072 KB
testcase_24 AC 1,036 ms
99,424 KB
testcase_25 AC 1,230 ms
102,236 KB
testcase_26 AC 1,094 ms
107,196 KB
testcase_27 AC 1,574 ms
109,156 KB
testcase_28 AC 1,247 ms
111,284 KB
testcase_29 AC 1,229 ms
111,284 KB
testcase_30 AC 1,064 ms
104,444 KB
testcase_31 AC 1,210 ms
111,416 KB
testcase_32 AC 1,188 ms
109,692 KB
testcase_33 AC 1,017 ms
101,276 KB
testcase_34 AC 1,242 ms
111,288 KB
testcase_35 AC 1,017 ms
101,700 KB
testcase_36 AC 1,241 ms
111,288 KB
testcase_37 AC 1,225 ms
111,412 KB
testcase_38 AC 997 ms
95,120 KB
testcase_39 AC 891 ms
88,712 KB
testcase_40 AC 982 ms
94,456 KB
testcase_41 AC 911 ms
88,912 KB
testcase_42 AC 1,069 ms
94,940 KB
testcase_43 AC 32 ms
11,136 KB
testcase_44 AC 97 ms
26,624 KB
testcase_45 AC 800 ms
75,264 KB
testcase_46 AC 929 ms
75,264 KB
testcase_47 AC 776 ms
75,392 KB
testcase_48 AC 832 ms
75,264 KB
testcase_49 AC 776 ms
75,264 KB
testcase_50 AC 767 ms
75,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import defaultdict, Counter, deque
from itertools import permutations, combinations, product, combinations_with_replacement, groupby, accumulate
import operator
from math import sqrt, gcd, factorial
# from math import isqrt, prod, comb  #python3.8用(notpypy)
#from bisect import bisect_left, bisect_right
#from functools import lru_cache, reduce
#from heapq import heappush, heappop, heapify, heappushpop, heapreplace
#import numpy as np
#import networkx as nx
#from networkx.utils import UnionFind
#from numba import njit, b1, i1, i4, i8, f8
# numba例 @njit(i1(i4[:], i8[:, :]),cache=True) 引数i4配列、i8 2次元配列,戻り値i1
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, NegativeCycleError, maximum_bipartite_matching, maximum_flow, minimum_spanning_tree
def input(): return sys.stdin.readline().rstrip()
def divceil(n, k): return 1+(n-1)//k  # n/kの切り上げを返す
def yn(hantei, yes='Yes', no='No'): print(yes if hantei else no)


def main():
    sys.setrecursionlimit(10**5+1)
    mod = 10**9+7
    mod2 = 998244353
    h, w, n = map(int, input().split())
    xy = [list(map(lambda x: int(x)-1, input().split())) for i in range(n)]
    graph = [[] for i in range(h+w)]
    for i, (x, y) in enumerate(xy):
        graph[x].append([y+h, i+1])
        graph[y+h].append([x, i+1])
    visited = [0]*(h+w)
    points = []
    edges = []

    def dfs(u, p):
        visited[u] = 1
        for v, num in graph[u]:
            if v != p:
                if visited[v]==1:
                    #print(points)
                    #print(edges)
                    if v<h:
                        ans=edges[points.index(v)+1:]+[num]
                    else:
                        ans=[num]+edges[points.index(v)+1:]
                    print(len(ans))
                    print(*ans)
                    #print(points)
                    #for aa in ans:
                    #    print(xy[aa-1][0],xy[aa-1][1]+h)
                    exit()
                points.append(v)
                edges.append(num)
                dfs(v, u)
        points.pop()
        edges.pop()

    for i in range(h):
        if visited[i]==0:
            points=[i]
            edges=[-1]
            #print(i)
            dfs(i, -1)
    print(-1)


if __name__ == '__main__':
    main()
0