結果
| 問題 | No.583 鉄道同好会 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2018-08-26 21:53:23 | 
| 言語 | Python2 (2.7.18) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 458 ms / 2,000 ms | 
| コード長 | 1,110 bytes | 
| コンパイル時間 | 507 ms | 
| コンパイル使用メモリ | 6,912 KB | 
| 実行使用メモリ | 10,240 KB | 
| 最終ジャッジ日時 | 2024-07-01 04:00:22 | 
| 合計ジャッジ時間 | 3,656 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 16 | 
ソースコード
n,m = map(int,raw_input().split())
class UnionFind():
    def __init__(self,size):
        self.table = [-1 for _  in range(size)]
    def find(self,x):
        while self.table[x] >= 0:
            x = self.table[x]
        return x
    def union(self,x,y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] != self.table[s2]:
                if self.table[s1] < self.table[s2]:
                    self.table[s2] = s1
                else:
                    self.table[s1] = s2
            else:
                self.table[s1] += -1
                self.table[s2] = s1
        return
degree = [0 for i in range(n)]
uf = UnionFind(n)
for i in range(m):
	f,t = map(int,raw_input().split())
	degree[f] += 1; degree[t] += 1
	uf.union(f,t)
a = -1
for i in range(n):
	if degree[i] > 0:
		a = i
		break
a = uf.find(a)
count = 0
for i in range(n):
	
	if degree[i] != 0 and uf.find(i) == a:
		if degree[i] % 2 == 1:
			count += 1
	elif degree[i] == 0:
		continue
	else: 
		print 'NO'
		quit()
if count == 0 or count == 2:
	print 'YES'
else :
	print 'NO'
            
            
            
        