結果
問題 | No.483 マッチ並べ |
ユーザー |
![]() |
提出日時 | 2021-05-25 22:29:45 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,742 bytes |
コンパイル時間 | 97 ms |
コンパイル使用メモリ | 13,056 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-10-14 13:26:12 |
合計ジャッジ時間 | 3,512 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 31 WA * 22 |
ソースコード
import sysinput = sys.stdin.buffer.readlinesys.setrecursionlimit(10 ** 7)class UF_tree:def __init__(self, n):self.root = [-1] * (n + 1)self.rank = [0] * (n + 1)def find(self, x):if self.root[x] < 0:return xself.root[x] = self.find(self.root[x])return self.root[x]def isSame(self, x, y):return self.find(x) == self.find(y)def unite(self, x, y):x = self.find(x)y = self.find(y)if x == y:return Falseif self.rank[x] < self.rank[y]:self.root[y] += self.root[x]self.root[x] = yelse:self.root[x] += self.root[y]self.root[y] = xif self.rank[x] == self.rank[y]:self.rank[x] += 1return Truedef size(self, x):return -self.root[self.find(x)]def touch(x, y, xx, yy):if x == xx:return Trueif y == yy:return Trueif x == yy:return Trueif y == xx:return Truereturn FalseN = int(input())match = tuple(tuple(map(int, input().split())) for _ in range(N))uf = UF_tree(N)G = [[] for _ in range(N)]cycle = 0for i in range(N):r, c, rr, cc = match[i]for j in range(i+1, N):rrr, ccc, rrrr, cccc = match[j]if touch((r, c), (rr, cc), (rrr, ccc), (rrrr, cccc)) and uf.unite(i, j):G[i].append(j)leader = {uf.find(i) for i in range(N)}group = {i: [] for i in leader}for i in range(N):group[uf.find(i)].append(i)ok = Truefor g in group.values():edge = 0for i in g:edge += len(G[i])if edge > len(g):ok = Falseif ok:print("YES")else:print("NO")