結果

問題 No.483 マッチ並べ
ユーザー titiatitia
提出日時 2023-06-07 04:21:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 928 bytes
コンパイル時間 685 ms
コンパイル使用メモリ 10,920 KB
実行使用メモリ 14,136 KB
最終ジャッジ日時 2023-08-28 12:10:26
合計ジャッジ時間 4,827 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
13,988 KB
testcase_01 AC 32 ms
13,920 KB
testcase_02 AC 36 ms
14,048 KB
testcase_03 AC 37 ms
13,996 KB
testcase_04 AC 35 ms
13,988 KB
testcase_05 AC 37 ms
13,920 KB
testcase_06 AC 32 ms
13,920 KB
testcase_07 AC 36 ms
14,128 KB
testcase_08 AC 36 ms
13,992 KB
testcase_09 AC 36 ms
13,960 KB
testcase_10 AC 37 ms
13,964 KB
testcase_11 AC 32 ms
13,952 KB
testcase_12 AC 31 ms
14,076 KB
testcase_13 AC 36 ms
13,924 KB
testcase_14 AC 37 ms
14,052 KB
testcase_15 AC 37 ms
13,920 KB
testcase_16 AC 32 ms
13,960 KB
testcase_17 AC 32 ms
13,920 KB
testcase_18 AC 37 ms
13,956 KB
testcase_19 AC 37 ms
14,052 KB
testcase_20 AC 32 ms
14,052 KB
testcase_21 AC 31 ms
13,984 KB
testcase_22 AC 31 ms
14,036 KB
testcase_23 AC 32 ms
14,104 KB
testcase_24 AC 32 ms
14,100 KB
testcase_25 AC 36 ms
14,128 KB
testcase_26 AC 36 ms
14,052 KB
testcase_27 AC 33 ms
14,056 KB
testcase_28 AC 32 ms
14,068 KB
testcase_29 AC 33 ms
14,080 KB
testcase_30 AC 36 ms
14,084 KB
testcase_31 AC 33 ms
14,116 KB
testcase_32 AC 32 ms
14,136 KB
testcase_33 AC 34 ms
13,968 KB
testcase_34 AC 33 ms
14,100 KB
testcase_35 AC 37 ms
13,960 KB
testcase_36 AC 37 ms
14,056 KB
testcase_37 AC 37 ms
13,920 KB
testcase_38 AC 37 ms
13,980 KB
testcase_39 AC 37 ms
13,924 KB
testcase_40 AC 32 ms
13,968 KB
testcase_41 AC 33 ms
13,960 KB
testcase_42 AC 31 ms
14,108 KB
testcase_43 AC 36 ms
14,088 KB
testcase_44 AC 37 ms
13,912 KB
testcase_45 AC 36 ms
14,096 KB
testcase_46 AC 35 ms
14,056 KB
testcase_47 AC 36 ms
14,004 KB
testcase_48 AC 37 ms
14,080 KB
testcase_49 AC 37 ms
13,920 KB
testcase_50 AC 36 ms
13,976 KB
testcase_51 AC 36 ms
14,064 KB
testcase_52 AC 38 ms
14,100 KB
testcase_53 AC 37 ms
13,964 KB
testcase_54 AC 33 ms
14,104 KB
testcase_55 AC 32 ms
13,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())

# UnionFind

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

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*110+b,c*110+d)

Point=[set() for i in range(20001)]
Edge=[0]*20001

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

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

print("YES")
0