結果
問題 |
No.483 マッチ並べ
|
ユーザー |
![]() |
提出日時 | 2021-02-14 23:14:01 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 48 ms / 2,000 ms |
コード長 | 1,327 bytes |
コンパイル時間 | 163 ms |
コンパイル使用メモリ | 82,192 KB |
実行使用メモリ | 60,148 KB |
最終ジャッジ日時 | 2024-07-22 11:10:07 |
合計ジャッジ時間 | 4,247 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 53 |
ソースコード
class UnionFind: def __init__(self, n): self.parent = list(range(n)) #親ノード self.size = [1]*n #グループの要素数 def root(self, x): #root(x): xの根ノードを返す. while self.parent[x] != x: self.parent[x] = self.parent[self.parent[x]] x = self.parent[x] return x def merge(self, x, y): #merge(x,y): xのいる組とyのいる組をまとめる x, y = self.root(x), self.root(y) if x == y: return False if self.size[x] < self.size[y]: x,y=y,x #xの要素数が大きいように self.size[x] += self.size[y] #xの要素数を更新 self.parent[y] = x #yをxにつなぐ return True def issame(self, x, y): #same(x,y): xとyが同じ組ならTrue return self.root(x) == self.root(y) def getsize(self,x): #size(x): xのいるグループの要素数を返す return self.size[self.root(x)] n = int(input()) M = 112 UF = UnionFind(M*M) res = [0]*(M*M) for _ in range(n): a,b,c,d = map(int,input().split()) v = (a-1)*M+b-1 w = (c-1)*M+d-1 if not UF.merge(v,w): res[v] += 1 for i in range(M*M): r = UF.root(i) if r != i: res[r] += res[i] if res[r] >= 2: print("NO") exit() print("YES")