結果

問題 No.583 鉄道同好会
ユーザー lllllll88938494lllllll88938494
提出日時 2022-09-17 13:14:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 164 ms / 2,000 ms
コード長 521 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 87,216 KB
実行使用メモリ 81,576 KB
最終ジャッジ日時 2023-08-23 17:40:43
合計ジャッジ時間 3,168 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,416 KB
testcase_01 AC 77 ms
71,456 KB
testcase_02 AC 73 ms
71,352 KB
testcase_03 AC 73 ms
71,412 KB
testcase_04 AC 74 ms
71,512 KB
testcase_05 AC 71 ms
71,216 KB
testcase_06 AC 73 ms
71,436 KB
testcase_07 AC 74 ms
71,536 KB
testcase_08 AC 75 ms
71,384 KB
testcase_09 AC 71 ms
71,452 KB
testcase_10 AC 78 ms
71,600 KB
testcase_11 AC 114 ms
77,952 KB
testcase_12 AC 118 ms
78,536 KB
testcase_13 AC 121 ms
78,544 KB
testcase_14 AC 122 ms
78,416 KB
testcase_15 AC 126 ms
78,828 KB
testcase_16 AC 153 ms
81,524 KB
testcase_17 AC 164 ms
81,576 KB
testcase_18 AC 162 ms
81,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m=map(int,input().split())
stations = [[] for i in range(n)]
ans =[0]*n

for i in range(m):
    a,b=map(int,input().split())
    stations[a].append(b)
    stations[b].append(a)
    ans[a] = 1
    ans[b] = 1
    if i == 0:start = a
    

cnt=0
for i in stations:
    if len(i)%2 == 1:
        cnt+=1

f=[0]*n
def  dfs(x):
    for i in stations[x]:
        if f[i] == 0:
            f[i] = 1
            dfs(i)
f[start] = 1
dfs(start)

if (f == ans) and (cnt == 0 or cnt == 2):
    print('YES')
else:
    print('NO')
    
0