結果
問題 | No.1612 I hate Construct a Palindrome |
ユーザー | ayaoni |
提出日時 | 2021-07-21 22:45:53 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,690 bytes |
コンパイル時間 | 178 ms |
コンパイル使用メモリ | 82,260 KB |
実行使用メモリ | 171,240 KB |
最終ジャッジ日時 | 2024-07-17 19:48:14 |
合計ジャッジ時間 | 10,850 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 286 ms
125,308 KB |
testcase_10 | AC | 319 ms
125,612 KB |
testcase_11 | AC | 361 ms
127,896 KB |
testcase_12 | AC | 408 ms
135,268 KB |
testcase_13 | AC | 410 ms
135,320 KB |
testcase_14 | WA | - |
testcase_15 | AC | 604 ms
170,200 KB |
testcase_16 | AC | 582 ms
171,240 KB |
testcase_17 | AC | 550 ms
170,856 KB |
testcase_18 | AC | 42 ms
56,832 KB |
testcase_19 | AC | 49 ms
63,580 KB |
testcase_20 | AC | 47 ms
64,432 KB |
testcase_21 | AC | 54 ms
68,432 KB |
testcase_22 | AC | 51 ms
65,684 KB |
testcase_23 | AC | 52 ms
67,256 KB |
testcase_24 | AC | 53 ms
67,320 KB |
testcase_25 | AC | 59 ms
70,312 KB |
testcase_26 | WA | - |
testcase_27 | AC | 38 ms
54,204 KB |
testcase_28 | AC | 39 ms
55,204 KB |
testcase_29 | AC | 37 ms
54,468 KB |
testcase_30 | AC | 36 ms
56,148 KB |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | AC | 37 ms
54,540 KB |
testcase_34 | AC | 38 ms
54,384 KB |
testcase_35 | AC | 37 ms
55,600 KB |
testcase_36 | AC | 37 ms
55,508 KB |
testcase_37 | AC | 36 ms
55,620 KB |
testcase_38 | AC | 36 ms
54,452 KB |
ソースコード
import sys from collections import deque sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int,sys.stdin.readline().rstrip())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def LS2(): return list(sys.stdin.readline().rstrip()) N,M = MI() Graph = [[] for _ in range(N+1)] edges = [] char = set() for i in range(1,M+1): A,B,C = S().split() A = int(A) B = int(B) Graph[A].append((B,C,i)) Graph[B].append((A,C,i)) edges.append((A,B,C)) char.add(C) if len(char) == 1: print(-1) exit() s,a,idx = Graph[1][0] for i in range(M): A,B,C = edges[i] if a != C: goal = A e = i+1 goal2 = B inf = 10**18 dist = [inf]*(N+1) dist[N] = (0,-1,-1) deq = deque([N]) while deq: u = deq.pop() if u == goal: break for v,_,i in Graph[u]: if dist[v] == inf: dist[v] = (dist[u][0]+1,i,u) deq.appendleft(v) ANS1 = [e] ss = goal while ss != N: d,i,u = dist[ss] ANS1.append(i) ss = u ANS0 = [idx]*len(ANS1) if len(ANS0) % 2 == 1: cur = s else: cur = 1 dist = [inf]*(N+1) dist[B] = (0,-1,-1) deq = deque([B]) while deq: u = deq.pop() if u == cur: break for v,_,i in Graph[u]: if dist[v] == inf: dist[v] = (dist[u][0]+1,i,u) deq.appendleft(v) s = cur while s != B: d,i,u = dist[s] ANS0.append(i) s = u ANS = ANS0+ANS1 print(len(ANS)) print(*ANS,sep='\n')