結果

問題 No.2072 Anatomy
ユーザー taiga0629kyoprotaiga0629kyopro
提出日時 2022-09-16 21:28:47
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,357 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 87,228 KB
実行使用メモリ 99,500 KB
最終ジャッジ日時 2023-08-23 14:27:15
合計ジャッジ時間 10,956 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,492 KB
testcase_01 AC 70 ms
71,416 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 234 ms
91,444 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 281 ms
94,588 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 249 ms
94,168 KB
testcase_22 WA -
testcase_23 AC 239 ms
93,764 KB
testcase_24 AC 247 ms
93,928 KB
testcase_25 WA -
testcase_26 AC 69 ms
71,336 KB
testcase_27 AC 234 ms
94,160 KB
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #







class unionfind:
    def __init__(self,uni_num):
        self.uni_num=uni_num
        self.union_root = [-1 for i in range(self.uni_num + 1)]
        self.union_depth = [0] * (self.uni_num + 1)
        self.e_num=[0]*(self.uni_num+1)

    def find(self,x):  # 親は誰?
        if self.union_root[x] < 0:
            return x
        else:
            self.union_root[x] = self.find(self.union_root[x])
            return self.union_root[x]

    def unite(self,x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            self.e_num[x]+=1
            return
        if self.union_depth[x] < self.union_depth[y]:
            x, y = y, x
        if self.union_depth[x] == self.union_depth[y]:
            self.union_depth[x] += 1
        self.union_root[x] += self.union_root[y]
        self.union_root[y] = x
        self.e_num[x]+=self.e_num[y]+1


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

    def same(self,x,y):
        return self.find(x)==self.find(y)
    def edge(self,x):
        return self.e_num[self.find(x)]



n,m=map(int,input().split())
e=[]
for i in range(m):
    u,v=map(int,input().split())
    e.append((u,v))
e.append((0,0))
e.reverse()
ans=1
uf=unionfind(n+3)
for i in range(1,m+1):
    u,v=e[i]
    bu,bv=e[i-1]
    uf.unite(u,v)
    if uf.same(u,bu):ans+=1
print(ans)



0