結果
問題 |
No.1370 置換門松列
|
ユーザー |
![]() |
提出日時 | 2021-01-29 23:41:16 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,163 bytes |
コンパイル時間 | 259 ms |
コンパイル使用メモリ | 82,516 KB |
実行使用メモリ | 101,224 KB |
最終ジャッジ日時 | 2024-11-08 04:17:32 |
合計ジャッジ時間 | 4,186 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 WA * 4 |
ソースコード
from collections import deque N,M = map(int,input().split()); INF = float("inf") A = list(map(int,input().split())) G = [[] for _ in range(M)] deg1 = [0] * M #入次数 deg2 = [0] * M #出次数 for i in range(N-1): a = A[i] - 1 #0index b = A[i+1] - 1 if a == b: print("No");exit() if i < N-2: c = A[i+2] - 1 if a == c: print("No");exit() if i%2 == 0: G[a].append(b) deg1[b] += 1 deg2[a] += 1 else: G[b].append(a) deg1[a] += 1 deg2[b] += 1 #print(G) def topological(start,graph): topo = [] start1 = deque(start) res = -INF while start1: v = start1.popleft() topo.append(v) for u in graph[v]: deg1[u] -= 1 if deg1[u] == 0: start1.append(u) # print(edges, minscore) return topo SG = [] used = [0] * M start = [] for i in range(M): if deg1[i] == 0 and deg2[i] > 0: SG.append(i) TS = topological(SG,G) #print(TS) if len(TS) < M: print("No") else: ans = [-1]*M for i, v in enumerate(TS): ans[v] = i + 1 print("Yes") print(*ans)