結果
問題 |
No.583 鉄道同好会
|
ユーザー |
👑 |
提出日時 | 2022-07-06 07:21:09 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 135 ms / 2,000 ms |
コード長 | 584 bytes |
コンパイル時間 | 284 ms |
コンパイル使用メモリ | 82,340 KB |
実行使用メモリ | 80,324 KB |
最終ジャッジ日時 | 2024-12-18 01:28:12 |
合計ジャッジ時間 | 2,412 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
n, m = map(int, input().split()) edges = [[] for _ in range(n)] for _ in range(m): u, v = map(int, input().split()) u -= 1 v -= 1 edges[u].append(v) edges[v].append(u) stack = [u] used = [False] * n used[u] = True while stack: pos = stack.pop() for npos in edges[pos]: if used[npos]: continue used[npos] = True stack.append(npos) odd = 0 for i in range(n): if not used[i] and edges[i]: print("NO") exit() if len(edges[i]) & 1: odd += 1 if odd <= 2: print("YES") else: print("NO")