結果

問題 No.583 鉄道同好会
ユーザー rin204
提出日時 2022-07-06 07:20:23
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 593 bytes
コンパイル時間 202 ms
コンパイル使用メモリ 82,008 KB
実行使用メモリ 80,084 KB
最終ジャッジ日時 2024-12-18 01:27:12
合計ジャッジ時間 2,165 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

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[npos] and edges[npos]:
        print("NO")
        exit()
    if len(edges[npos]) & 1:
        odd += 1
if odd <= 2:
    print("YES")
else:
    print("NO")
0