結果

問題 No.1390 Get together
ユーザー kazu_eykazu_ey
提出日時 2021-02-13 01:57:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,380 bytes
コンパイル時間 83 ms
コンパイル使用メモリ 11,004 KB
実行使用メモリ 56,132 KB
最終ジャッジ日時 2023-09-27 09:14:07
合計ジャッジ時間 13,467 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
8,336 KB
testcase_01 AC 15 ms
8,376 KB
testcase_02 AC 15 ms
8,456 KB
testcase_03 AC 25 ms
9,368 KB
testcase_04 AC 24 ms
9,068 KB
testcase_05 WA -
testcase_06 AC 25 ms
8,984 KB
testcase_07 WA -
testcase_08 AC 22 ms
9,064 KB
testcase_09 AC 25 ms
9,352 KB
testcase_10 AC 14 ms
8,296 KB
testcase_11 AC 15 ms
8,356 KB
testcase_12 AC 14 ms
8,320 KB
testcase_13 WA -
testcase_14 AC 15 ms
8,424 KB
testcase_15 AC 15 ms
8,356 KB
testcase_16 WA -
testcase_17 AC 717 ms
55,488 KB
testcase_18 AC 750 ms
55,484 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 692 ms
56,124 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 696 ms
56,084 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFind:
    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n

    def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]

    def unite(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if x==y:
            return
        if self.parents[x]>self.parents[y]:
            x,y=y,x
        self.parents[x]+=self.parents[y]
        self.parents[y]=x

    def same(self,x,y):
        return self.find(x)==self.find(y)

    def size(self,x):
        return -self.parents[self.find(x)]

    def members(self,x):
        root=self.find(x)
        return [i for i in range(self.n) if self.find(i)==root]

    def roots(self):
        return [i for i,x in enumerate(self.parents) if x<0]

    def groups(self):
        group=[[] for _ in range(self.n)]
        for i in range(self.n):
            group[self.find(i)].append(i)
        return [g for g in group if g]


import sys
input=sys.stdin.readline
n,m=map(int,input().split())
max_lst=[0]*n
uf=UnionFind(n)
bc=sorted([tuple(map(int,input().split())) for _ in range(n)],key=lambda x:(x[1],x[0]))
for i in range(1,n):
    if bc[i-1]==bc[i]:
            uf.unite(i-1,i)
for i in range(n):
    s=uf.size(i)
    max_lst[bc[i][1]-1]=max(max_lst[bc[i][1]-1],s)
print(n-sum(max_lst))
0