結果
問題 | No.583 鉄道同好会 |
ユーザー | rlangevin |
提出日時 | 2023-02-20 01:29:46 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 108 ms / 2,000 ms |
コード長 | 1,253 bytes |
コンパイル時間 | 303 ms |
コンパイル使用メモリ | 87,148 KB |
実行使用メモリ | 77,356 KB |
最終ジャッジ日時 | 2023-09-28 03:32:40 |
合計ジャッジ時間 | 3,306 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 68 ms
71,092 KB |
testcase_01 | AC | 68 ms
71,480 KB |
testcase_02 | AC | 66 ms
71,588 KB |
testcase_03 | AC | 69 ms
71,268 KB |
testcase_04 | AC | 67 ms
71,228 KB |
testcase_05 | AC | 67 ms
71,584 KB |
testcase_06 | AC | 67 ms
71,308 KB |
testcase_07 | AC | 69 ms
71,528 KB |
testcase_08 | AC | 69 ms
71,260 KB |
testcase_09 | AC | 66 ms
71,284 KB |
testcase_10 | AC | 69 ms
71,248 KB |
testcase_11 | AC | 88 ms
77,292 KB |
testcase_12 | AC | 89 ms
77,072 KB |
testcase_13 | AC | 86 ms
77,252 KB |
testcase_14 | AC | 87 ms
77,320 KB |
testcase_15 | AC | 95 ms
77,356 KB |
testcase_16 | AC | 100 ms
77,012 KB |
testcase_17 | AC | 107 ms
77,276 KB |
testcase_18 | AC | 108 ms
77,300 KB |
ソースコード
import sys readline = sys.stdin.readline class UnionFind(object): def __init__(self, n=1): self.par = [i for i in range(n)] self.rank = [0 for _ in range(n)] self.size = [1 for _ in range(n)] def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x != y: if self.rank[x] < self.rank[y]: x, y = y, x if self.rank[x] == self.rank[y]: self.rank[x] += 1 self.par[y] = x self.size[x] += self.size[y] def is_same(self, x, y): return self.find(x) == self.find(y) def get_size(self, x): x = self.find(x) return self.size[x] N, M = map(int, readline().split()) G = [0] * N U = UnionFind(N) for i in range(M): u, v = map(int, readline().split()) G[u] += 1 G[v] += 1 U.union(u, v) odd = 0 cnt = 0 maxv = 0 for i in range(N): if G[i] % 2: odd += 1 if G[i]: cnt += 1 maxv = max(maxv, U.get_size(i)) if odd <= 2 and maxv == cnt: print("YES") else: print("NO")