結果

問題 No.483 マッチ並べ
ユーザー titia
提出日時 2023-06-07 04:16:14
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 912 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-12-29 10:43:12
合計ジャッジ時間 4,039 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39 WA * 13 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())

# UnionFind

Group = [i for i in range(10001)] # グループ分け
Nodes = [1]*(10001) # 各グループのノードの数

def find(x):
    while Group[x] != x:
        x=Group[x]
    return x

def Union(x,y):
    if find(x) != find(y):
        if Nodes[find(x)] < Nodes[find(y)]:
            
            Nodes[find(y)] += Nodes[find(x)]
            Nodes[find(x)] = 0
            Group[find(x)] = find(y)
            
        else:
            Nodes[find(x)] += Nodes[find(y)]
            Nodes[find(y)] = 0
            Group[find(y)] = find(x)

P=[list(map(int,input().split())) for i in range(N)]
for a,b,c,d in P:
    Union(a*100+b,c*100+d)

Point=[set()]*10001
Edge=[0]*10001

for a,b,c,d in P:
    x=find(a*100+b)
    Edge[x]+=1
    Point[x].add(a*100+b)
    Point[x].add(c*100+d)

for i in range(10001):
    if len(Point[i])+1<=Edge[i]:
        print("NO")
        exit()

print("YES")
0