結果
問題 | No.583 鉄道同好会 |
ユーザー | nebukuro09 |
提出日時 | 2017-10-28 03:38:20 |
言語 | Python2 (2.7.18) |
結果 |
AC
|
実行時間 | 793 ms / 2,000 ms |
コード長 | 944 bytes |
コンパイル時間 | 278 ms |
コンパイル使用メモリ | 6,708 KB |
実行使用メモリ | 6,044 KB |
最終ジャッジ日時 | 2023-08-14 05:52:11 |
合計ジャッジ時間 | 6,053 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 11 ms
6,032 KB |
testcase_01 | AC | 11 ms
5,776 KB |
testcase_02 | AC | 11 ms
5,996 KB |
testcase_03 | AC | 12 ms
6,044 KB |
testcase_04 | AC | 21 ms
5,952 KB |
testcase_05 | AC | 11 ms
5,972 KB |
testcase_06 | AC | 11 ms
5,780 KB |
testcase_07 | AC | 11 ms
5,828 KB |
testcase_08 | AC | 11 ms
5,992 KB |
testcase_09 | AC | 12 ms
5,980 KB |
testcase_10 | AC | 12 ms
5,884 KB |
testcase_11 | AC | 428 ms
5,916 KB |
testcase_12 | AC | 472 ms
6,004 KB |
testcase_13 | AC | 468 ms
5,888 KB |
testcase_14 | AC | 470 ms
5,976 KB |
testcase_15 | AC | 517 ms
5,972 KB |
testcase_16 | AC | 708 ms
5,996 KB |
testcase_17 | AC | 793 ms
5,840 KB |
testcase_18 | AC | 789 ms
6,024 KB |
ソースコード
class UnionFind(object): def __init__(self, n): self.table = [-1 for _ in xrange(n)] def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.table[x] >= self.table[y]: self.table[y] += self.table[x] self.table[x] = y else: self.table[x] += self.table[y] self.table[y] = x def find(self, x): if self.table[x] < 0: return x self.table[x] = self.find(self.table[x]) return self.table[x] N, M = map(int, raw_input().split()) D = [0 for _ in xrange(N)] U = UnionFind(N) for _ in xrange(M): a, b = map(int, raw_input().split()) D[a] += 1 D[b] += 1 U.unite(a, b) union = all(U.find(a) == U.find(b) for a in xrange(N) for b in xrange(N) if D[a] > 0 and D[b] > 0) odd = sum(d % 2 for d in D) print "YES" if (odd == 0 or odd == 2) and union else "NO"