結果

問題 No.583 鉄道同好会
ユーザー 👑 rin204rin204
提出日時 2022-07-06 07:21:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 584 bytes
コンパイル時間 346 ms
コンパイル使用メモリ 87,320 KB
実行使用メモリ 81,028 KB
最終ジャッジ日時 2023-08-22 22:46:05
合計ジャッジ時間 3,331 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,188 KB
testcase_01 AC 71 ms
71,200 KB
testcase_02 AC 72 ms
71,228 KB
testcase_03 AC 72 ms
70,968 KB
testcase_04 AC 74 ms
71,184 KB
testcase_05 AC 72 ms
71,048 KB
testcase_06 AC 73 ms
71,140 KB
testcase_07 AC 72 ms
70,840 KB
testcase_08 AC 71 ms
71,200 KB
testcase_09 AC 72 ms
71,200 KB
testcase_10 AC 74 ms
71,244 KB
testcase_11 AC 116 ms
77,424 KB
testcase_12 AC 122 ms
78,112 KB
testcase_13 AC 122 ms
77,992 KB
testcase_14 AC 123 ms
77,724 KB
testcase_15 AC 129 ms
78,012 KB
testcase_16 AC 154 ms
81,028 KB
testcase_17 AC 165 ms
80,960 KB
testcase_18 AC 162 ms
80,884 KB
権限があれば一括ダウンロードができます

ソースコード

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