結果
問題 | No.1610 She Loves Me, She Loves Me Not, ... |
ユーザー |
![]() |
提出日時 | 2025-03-26 15:46:29 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 122 ms / 2,000 ms |
コード長 | 2,159 bytes |
コンパイル時間 | 212 ms |
コンパイル使用メモリ | 82,444 KB |
実行使用メモリ | 79,676 KB |
最終ジャッジ日時 | 2025-03-26 15:46:59 |
合計ジャッジ時間 | 3,653 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
ソースコード
import sysfrom collections import dequedef main():input = sys.stdin.read().split()idx = 0N = int(input[idx])idx += 1M = int(input[idx])idx += 1adj = [[] for _ in range(N + 1)]for _ in range(M):a = int(input[idx])idx += 1b = int(input[idx])idx += 1adj[a].append(b)adj[b].append(a)# Find connected componentsvisited = [False] * (N + 1)components = []for u in range(1, N + 1):if not visited[u]:q = deque()q.append(u)visited[u] = Truecomp = set()comp.add(u)while q:v = q.popleft()for nei in adj[v]:if not visited[nei]:visited[nei] = Truecomp.add(nei)q.append(nei)components.append(comp)total_steps = 0for comp in components:# Compute edges_in_Cedges_in_C = 0for u in comp:for v in adj[u]:if v in comp and u < v:edges_in_C += 1# Compute degreesdegree = {u: 0 for u in comp}for u in comp:cnt = 0for v in adj[u]:if v in comp:cnt += 1degree[u] = cnt# Process queueq = deque()for u in comp:if degree[u] == 1:q.append(u)while q:u = q.popleft()if degree[u] != 1:continuefor v in adj[u]:if v not in comp:continueif degree[v] == 0:continuedegree[v] -= 1if degree[v] == 1:q.append(v)degree[u] = 0sum_deg = sum(degree.values())edges_2core = sum_deg // 2steps = edges_in_C - edges_2coretotal_steps += stepsif total_steps % 2 == 1:print("Yes")else:print("No")if __name__ == "__main__":main()