結果
問題 | No.583 鉄道同好会 |
ユーザー | daleksprinter |
提出日時 | 2018-08-26 21:53:23 |
言語 | Python2 (2.7.18) |
結果 |
AC
|
実行時間 | 447 ms / 2,000 ms |
コード長 | 1,110 bytes |
コンパイル時間 | 841 ms |
コンパイル使用メモリ | 6,520 KB |
実行使用メモリ | 9,748 KB |
最終ジャッジ日時 | 2023-09-13 19:24:08 |
合計ジャッジ時間 | 4,026 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 11 ms
5,924 KB |
testcase_01 | AC | 11 ms
5,920 KB |
testcase_02 | AC | 12 ms
5,932 KB |
testcase_03 | AC | 11 ms
5,996 KB |
testcase_04 | AC | 11 ms
5,948 KB |
testcase_05 | AC | 11 ms
5,888 KB |
testcase_06 | AC | 11 ms
5,844 KB |
testcase_07 | AC | 11 ms
6,048 KB |
testcase_08 | AC | 11 ms
5,964 KB |
testcase_09 | AC | 12 ms
5,892 KB |
testcase_10 | AC | 12 ms
5,996 KB |
testcase_11 | AC | 118 ms
6,876 KB |
testcase_12 | AC | 161 ms
7,120 KB |
testcase_13 | AC | 157 ms
7,032 KB |
testcase_14 | AC | 162 ms
7,072 KB |
testcase_15 | AC | 206 ms
7,248 KB |
testcase_16 | AC | 375 ms
8,908 KB |
testcase_17 | AC | 447 ms
9,748 KB |
testcase_18 | AC | 446 ms
9,632 KB |
ソースコード
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'