結果
問題 | No.3031 曲面の向き付け |
ユーザー |
![]() |
提出日時 | 2025-02-21 22:22:01 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,042 bytes |
コンパイル時間 | 346 ms |
コンパイル使用メモリ | 83,028 KB |
実行使用メモリ | 262,108 KB |
最終ジャッジ日時 | 2025-02-21 22:22:21 |
合計ジャッジ時間 | 5,979 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 6 WA * 1 TLE * 1 -- * 21 |
ソースコード
from collections import dequedef scc(N, G, RG):order = []used = [0]*Ndef dfs(s):used[s] = 1for t in G[s]:if not used[t]:dfs(t)order.append(s)for i in range(N):if not used[i]:dfs(i)group = [-1]*Nlabel = 0order.reverse()for s in order:if group[s] != -1:continueque = deque([s])group[s] = labelwhile que:v = que.popleft()for w in RG[v]:if group[w] != -1:continueque.append(w)group[w] = labellabel += 1return group # topological orderingN = int(input())G = [[] for i in range(2*N)]RG = [[] for i in range(2*N)]tri = [tuple(map(int, input().split())) for _ in range(N)]from collections import defaultdictdict = defaultdict(lambda:[])def add_edge(i, neg_i, j, neg_j):if neg_i:i0 = i+N; i1 = ielse:i0 = i; i1 = i+Nif neg_j:j0 = j+N; j1 = jelse:j0 = j; j1 = j+N# add (~a ⇒ b)G[i1].append(j0); RG[j0].append(i1)# add (~b ⇒ a)G[j1].append(i0); RG[i0].append(j1)for i in range(N):a, b, c = tri[i]for u, v in [(a, b), (b, c)]:dict[(u, v)].append((i, 1))dict[(a, c)].append((i, 0))for u, v in dict:if len(dict[(u, v)]) >= 3:print("NO")exit()elif len(dict[(u, v)]) == 2:i0, t0 = dict[(u, v)][0]i1, t1 = dict[(u, v)][1]if t0 == t1:add_edge(i0, True, i1, False)add_edge(i0, False, i1, True)else:add_edge(i0, True, i1, True)add_edge(i0, False, i1, False)group = scc(2*N, G, RG)# check if the formula is satisfiabledef check(group):for i in range(N):if group[i] == group[i+N]:return Falsereturn Trueif check(group):print("YES")else:print("NO")