結果

問題 No.583 鉄道同好会
ユーザー posaune-0xa0posaune-0xa0
提出日時 2018-06-29 01:50:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 648 bytes
コンパイル時間 113 ms
コンパイル使用メモリ 10,836 KB
実行使用メモリ 15,456 KB
最終ジャッジ日時 2023-09-13 15:03:22
合計ジャッジ時間 3,130 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 16 ms
7,900 KB
testcase_02 AC 16 ms
7,896 KB
testcase_03 AC 15 ms
7,860 KB
testcase_04 AC 15 ms
7,856 KB
testcase_05 AC 16 ms
7,816 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 15 ms
7,780 KB
testcase_09 AC 16 ms
7,816 KB
testcase_10 AC 17 ms
7,816 KB
testcase_11 AC 104 ms
9,864 KB
testcase_12 AC 141 ms
10,608 KB
testcase_13 AC 136 ms
10,616 KB
testcase_14 AC 137 ms
10,660 KB
testcase_15 AC 179 ms
11,412 KB
testcase_16 AC 327 ms
14,312 KB
testcase_17 AC 391 ms
15,456 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
vt = [0]*N
visited = [False]*N
adj = [[] for i in range(N)]
for i in range(M):
    Sa, Sb = map(int, input().split())
    adj[Sa].append(Sb)
    adj[Sb].append(Sa)
    vt[Sa] += 1
    vt[Sb] += 1

def dfs(v):
    if not visited[v]:
        visited[v] = True
        for u in adj[v]:
            if not visited[u]:
                dfs(u)

for i in range(N):
    if vt[i] != 0:
        dfs(i)
        break

connected = True
for i in range(N):
    if vt[i] == 0 and not visited[i]:
        connected = False
        break

if connected and [x%2 for x in vt].count(1) in {0, 2}:
    print('YES')
else:
    print('NO')
0