4 solutions

  • 0
    @ 2023-7-16 14:38:22
    #include <bits/stdc++.h>
    #define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    #define re register
    using namespace std;
    typedef long long ll;
    int fth[1000010], n, m, x, y, tx, ty, ans, cnt[1000010];
    int fnd(int t)
    {
    	return (fth[t]==t?t:fth[t]=fnd(fth[t]));
    }
    int main()
    {
    	IOS;
    	cin>>n>>m;
    	for(int i=0; i<=n; i++) fth[i]=i;
    	for(int i=0; i<m; i++)
    	{
    		cin>>x>>y;
    		tx=fnd(x), ty=fnd(y);
    		if(tx!=ty) fth[ty]=tx;
    	}
    	for(int i=1; i<=n; i++) cnt[fnd(i)]++, ans=max(ans, cnt[fnd(i)]);
    	cout<<ans;
    	return 0;
    }
    

    Information

    ID
    455
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    2
    Tags
    # Submissions
    128
    Accepted
    58
    Uploaded By