#44194: python


suyueh (suyueh)

學校 : 不指定學校
編號 : 272111
來源 : [101.12.160.127]
最後登入時間 :
2024-11-21 22:51:47
o067. 柯尼斯堡七橋問題 -- Wikipedia板橋高中教學題 | From: [111.242.18.129] | 發表日期 : 2024-11-11 19:29

# Read input values
n, m = map(int, input().split())
degrees = [0] * n

# Build the graph and count the degree of each vertex
for _ in range(m):
    u, v = map(int, input().split())
    degrees[u - 1] += 1
    degrees[v - 1] += 1

# Count vertices with an odd degree
odd_count = sum(1 for degree in degrees if degree % 2 != 0)

# Check Eulerian path conditions
if odd_count == 0 or odd_count == 2:
    print("YES")
else:
    print("NO")

 
ZeroJudge Forum