結果
問題 | No.2536 同値性と充足可能性 |
ユーザー |
|
提出日時 | 2023-11-10 22:12:03 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 307 ms / 2,000 ms |
コード長 | 1,479 bytes |
コンパイル時間 | 222 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 106,880 KB |
最終ジャッジ日時 | 2024-09-26 01:40:54 |
合計ジャッジ時間 | 5,161 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 31 |
ソースコード
import syssys.setrecursionlimit(5*10**5)input = sys.stdin.readlinefrom collections import defaultdict, deque, Counterfrom heapq import heappop, heappushfrom bisect import bisect_left, bisect_rightfrom math import gcdfrom collections import defaultdictn,m = map(int,input().split())graph = [[] for i in range(n+1)]for i in range(m):u, e, v = map(str,input().split())u = int(u)v = int(v)if e == "<=/=>":graph[u].append((v,1))graph[v].append((u,1))else:graph[u].append((v,0))graph[v].append((u,0))depth = [-1]*(n+1)def bfs(s, n):que = deque([s])depth[s] = 0ok = 1ss = set()while que:crr = que.popleft()ss.add(crr)for nxt,w in graph[crr]:if depth[nxt] == -1:depth[nxt] = depth[crr]^wque.append(nxt)else:if depth[nxt] != depth[crr]^w:ok = 0return ok, ssbig = []ok = 1for i in range(1, n+1):if depth[i] != -1: continueoki, s = bfs(i, n)ok &= okio = []z = []for j in s:if depth[j] == 1:o.append(j)elif depth[j] == 0:z.append(j)if len(o) > len(z):big += oelse:big += zif not ok:print('No')else:for i in range(1, n+1):if depth[i] == -1:big.append(i)print('Yes')big.sort()print(len(big))print(*big)