結果
問題 | No.2664 Prime Sum |
ユーザー | 👑 rin204 |
提出日時 | 2024-03-08 21:03:19 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 94 ms / 2,000 ms |
コード長 | 1,120 bytes |
コンパイル時間 | 170 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 77,696 KB |
最終ジャッジ日時 | 2024-09-29 18:49:28 |
合計ジャッジ時間 | 3,341 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 37 |
ソースコード
class UnionFind:def __init__(self, n):self.n = nself.par = [-1] * nself.group_ = ndef find(self, x):if self.par[x] < 0:return xlst = []while self.par[x] >= 0:lst.append(x)x = self.par[x]for y in lst:self.par[y] = xreturn xdef unite(self, x, y):x = self.find(x)y = self.find(y)if x == y:return Falseif self.par[x] > self.par[y]:x, y = y, xself.par[x] += self.par[y]self.par[y] = xself.group_ -= 1return Truedef size(self, x):return -self.par[self.find(x)]def same(self, x, y):return self.find(x) == self.find(y)@propertydef group(self):return self.group_n, m = map(int, input().split())UF = UnionFind(2 * n)for _ in range(m):a, b = map(int, input().split())a -= 1b -= 1UF.unite(a, b + n)UF.unite(a + n, b)for i in range(n):if UF.same(i, i + n):print("No")exit()print("Yes")