結果
| 問題 |
No.483 マッチ並べ
|
| コンテスト | |
| ユーザー |
tktk_snsn
|
| 提出日時 | 2021-05-25 22:13:49 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,498 bytes |
| コンパイル時間 | 87 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 11,008 KB |
| 最終ジャッジ日時 | 2024-10-14 13:12:05 |
| 合計ジャッジ時間 | 3,615 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 WA * 29 |
ソースコード
import sys
input = sys.stdin.buffer.readline
sys.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 x
self.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 False
if self.rank[x] < self.rank[y]:
self.root[y] += self.root[x]
self.root[x] = y
else:
self.root[x] += self.root[y]
self.root[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
return True
def size(self, x):
return -self.root[self.find(x)]
def touch(x, y, xx, yy):
if x == xx:
return True
if y == yy:
return True
if x == yy:
return True
if y == xx:
return True
return False
N = int(input())
uf = UF_tree(N)
match = tuple(tuple(map(int, input().split())) for _ in range(N))
cycle = 0
for i in range(N):
r, c, rr, cc = match[i]
for j in range(i+1, N):
rrr, ccc, rrrr, cccc = match[j]
if not touch((r, c), (rr, cc), (rrr, ccc), (rrrr, cccc)):
continue
if not uf.unite(i, j):
cycle += 1
if cycle < 2:
print("YES")
else:
print("NO")
tktk_snsn