結果
問題 | No.1612 I hate Construct a Palindrome |
ユーザー | ayaoni |
提出日時 | 2021-07-21 22:40:13 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,686 bytes |
コンパイル時間 | 222 ms |
コンパイル使用メモリ | 82,440 KB |
実行使用メモリ | 171,468 KB |
最終ジャッジ日時 | 2024-07-17 19:41:58 |
合計ジャッジ時間 | 13,123 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 332 ms
125,160 KB |
testcase_10 | AC | 386 ms
125,284 KB |
testcase_11 | AC | 393 ms
127,936 KB |
testcase_12 | AC | 480 ms
135,904 KB |
testcase_13 | AC | 458 ms
135,204 KB |
testcase_14 | WA | - |
testcase_15 | AC | 713 ms
169,908 KB |
testcase_16 | WA | - |
testcase_17 | AC | 625 ms
170,712 KB |
testcase_18 | WA | - |
testcase_19 | AC | 53 ms
64,236 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 53 ms
66,376 KB |
testcase_23 | WA | - |
testcase_24 | AC | 57 ms
67,496 KB |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | AC | 41 ms
54,668 KB |
testcase_28 | AC | 44 ms
54,332 KB |
testcase_29 | AC | 42 ms
54,548 KB |
testcase_30 | AC | 41 ms
55,036 KB |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | AC | 41 ms
54,880 KB |
testcase_36 | AC | 41 ms
54,948 KB |
testcase_37 | WA | - |
testcase_38 | WA | - |
ソースコード
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] s = goal while s != N: d,i,u = dist[s] ANS1.append(i) s = 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')