結果
問題 | No.1647 Travel in Mitaru city 2 |
ユーザー | mkawa2 |
提出日時 | 2021-08-13 23:31:07 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 421 ms / 2,500 ms |
コード長 | 1,750 bytes |
コンパイル時間 | 1,673 ms |
コンパイル使用メモリ | 81,664 KB |
実行使用メモリ | 131,592 KB |
最終ジャッジ日時 | 2024-10-13 03:23:44 |
合計ジャッジ時間 | 18,926 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
53,976 KB |
testcase_01 | AC | 37 ms
53,412 KB |
testcase_02 | AC | 38 ms
52,636 KB |
testcase_03 | AC | 40 ms
53,496 KB |
testcase_04 | AC | 58 ms
69,236 KB |
testcase_05 | AC | 39 ms
52,988 KB |
testcase_06 | AC | 41 ms
54,240 KB |
testcase_07 | AC | 62 ms
72,668 KB |
testcase_08 | AC | 384 ms
116,904 KB |
testcase_09 | AC | 310 ms
109,132 KB |
testcase_10 | AC | 387 ms
116,468 KB |
testcase_11 | AC | 327 ms
112,780 KB |
testcase_12 | AC | 357 ms
116,288 KB |
testcase_13 | AC | 303 ms
107,304 KB |
testcase_14 | AC | 395 ms
127,780 KB |
testcase_15 | AC | 389 ms
119,324 KB |
testcase_16 | AC | 374 ms
124,960 KB |
testcase_17 | AC | 336 ms
114,220 KB |
testcase_18 | AC | 325 ms
110,324 KB |
testcase_19 | AC | 367 ms
116,472 KB |
testcase_20 | AC | 335 ms
111,344 KB |
testcase_21 | AC | 320 ms
111,488 KB |
testcase_22 | AC | 419 ms
130,288 KB |
testcase_23 | AC | 414 ms
130,044 KB |
testcase_24 | AC | 350 ms
112,896 KB |
testcase_25 | AC | 383 ms
116,544 KB |
testcase_26 | AC | 419 ms
130,560 KB |
testcase_27 | AC | 419 ms
130,424 KB |
testcase_28 | AC | 416 ms
130,564 KB |
testcase_29 | AC | 411 ms
130,564 KB |
testcase_30 | AC | 400 ms
126,568 KB |
testcase_31 | AC | 421 ms
131,592 KB |
testcase_32 | AC | 332 ms
112,640 KB |
testcase_33 | AC | 361 ms
114,176 KB |
testcase_34 | AC | 419 ms
131,584 KB |
testcase_35 | AC | 300 ms
108,552 KB |
testcase_36 | AC | 404 ms
131,584 KB |
testcase_37 | AC | 399 ms
130,692 KB |
testcase_38 | AC | 395 ms
121,992 KB |
testcase_39 | AC | 325 ms
109,088 KB |
testcase_40 | AC | 389 ms
121,368 KB |
testcase_41 | AC | 362 ms
114,440 KB |
testcase_42 | AC | 393 ms
120,336 KB |
testcase_43 | AC | 47 ms
62,904 KB |
testcase_44 | AC | 45 ms
65,340 KB |
testcase_45 | AC | 270 ms
108,236 KB |
testcase_46 | AC | 351 ms
108,024 KB |
testcase_47 | AC | 275 ms
108,116 KB |
testcase_48 | AC | 314 ms
107,908 KB |
testcase_49 | AC | 263 ms
107,596 KB |
testcase_50 | AC | 269 ms
107,616 KB |
ソースコード
import sys sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] # inf = 10**16 md = 998244353 # md = 10**9+7 h, w, n = LI() to = [[] for _ in range(h+w)] xytoi = {} for i in range(n): x, y = LI1() y += h to[x].append(y) to[y].append(x) xytoi[x, y] = i vis = [0]*(h+w) def dfs(u): stack = [(u, -1, True)] res = [] while stack: u, par, first = stack.pop() if first: vis[u] = 1 stack.append((u, par, False)) for v in to[u]: if v == par: continue if vis[v] == 2: continue if vis[v] == 1: res = [v, u, par] break stack.append((v, u, True)) else: if res and res[-1] == u: res.append(par) if res and res[0] == res[-1]: return res vis[u] = 2 ans = [] for u in range(h): if vis[u]: continue uu = dfs(u) if uu: for u0, u1 in zip(uu, uu[1:]): if u0 > u1: u0, u1 = u1, u0 i = xytoi[u0, u1] ans.append(i+1) if uu[0] > uu[1]: ans = [ans[-1]]+ans[:-1] break if ans: print(len(ans)) print(*ans) else: print(-1)