結果
| 問題 | No.2072 Anatomy | 
| コンテスト | |
| ユーザー |  kuro_B | 
| 提出日時 | 2023-03-05 23:35:27 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 521 ms / 2,000 ms | 
| コード長 | 2,872 bytes | 
| コンパイル時間 | 258 ms | 
| コンパイル使用メモリ | 82,432 KB | 
| 実行使用メモリ | 119,280 KB | 
| 最終ジャッジ日時 | 2024-09-18 01:42:16 | 
| 合計ジャッジ時間 | 10,085 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 27 | 
ソースコード
###スニペット始まり###
import sys, re
from math import ceil, floor, sqrt,factorial, gcd, pi, degrees, radians, sin, asin, cos, acos, tan, atan2
from collections import Counter, deque, defaultdict
from heapq import heapify, heappop, heappush
from itertools import permutations, accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce, lru_cache
from string import ascii_uppercase, ascii_lowercase
from decimal import Decimal, ROUND_HALF_UP #四捨五入用
def input(): return sys.stdin.readline().rstrip('\n')
#easy-testでは再帰数を下げる。
if __file__=='prog.py':
    sys.setrecursionlimit(10**5)
else:
    sys.setrecursionlimit(10**6)
def lcm(a, b): return a * b // gcd(a, b)
#3つ以上の最大公約数/最小公倍数
def gcd_v2(l: list): return reduce(gcd, l)
def lcm_v2(l: list): return reduce(lcm, l)
#nPk
def nPk(n, k): return factorial(n) // factorial(n - k)
#逆元
def modinv(a, mod=10**9+7): return pow(a, mod-2, mod)
INF = float('inf')
MOD = 10 ** 9 + 7
###スニペット終わり###
#0-index
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 union(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 size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    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 group_count(self):
        return len(self.roots())
    def all_group_members(self):
        group_members = defaultdict(list)
        for member in range(self.n):
            group_members[self.find(member)].append(member)
        return group_members
    def __str__(self):
        return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items())
N, M = map(int, input().split())
e=[]
for _ in range(M):
    a, b = map(int, input().split())
    e.append([a-1, b-1])
cnt=[0]*N #必要な操作回数
uf=UnionFind(N)
#逆から見ていく。
for a, b in e[::-1]:
    #逆から見る
    if uf.same(a,b):
        cnt[uf.find(a)]+=1 #親に加算
    else:
        pa=uf.find(a)
        pb=uf.find(b)
        uf.union(a,b) #結合
        np=uf.find(a) #新しい親
        cnt[np]=max(cnt[pa], cnt[pb])+1 #更新する
print(max(cnt))
            
            
            
        