跳到正文

个人记录

ddd

yhlj24444约 3 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 3 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
#include<algorithm>
#define sz size
#define pb push_back
#define bg begin
#define ed end
#define pc putchar
#define int long long
//#define getchar getchar_unlocked
//#define putchar putchar_unlocked
typedef long long lli;
typedef double lf;
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
inline void write(int x)
{
	if(x<0){x=~(x-1);putchar('-');}
	if(x>9)write(x/10);
	putchar(x%10+48);
}
vector<int> g[100001];
int fa[100001];
int find_(int x)
{
	if(fa[x]==x)return x;
	else return fa[x]=find_(fa[x]);
}
int cnt[100001];
signed main()
{
    ios::sync_with_stdio(0);
 	cin.tie(0),cout.tie(0);
 	int n;
 	cin>>n;
 	for(int i=1;i<=n;i++)
	{
		int x,y;
		cin>>x;
		while(x--)cin>>y,g[i].pb(y);

	}
	for(int i=1;i<=n;i++)fa[i]=i,cnt[i]=1;
	for(int i=n;i>=1;i--)
	{
        int fi=find_(i);
		for(int j=0;j<g[i].sz();j++)
		{
			if(find_(g[i][j])!=fi)
			{
				//cnt[fi]+=cnt[find_(g[i][j])];
                //cout<<i<<"-"<<g[i][j]<<":"<<cnt[fi]<<"+"<<cnt[find_(g[i][j])]<<endl;
                cnt[fi]+=cnt[find_(g[i][j])];
                fa[g[i][j]]=fi;
                //cout<<cnt
				if(cnt[fi]>n/2.0)cout<<g[i][j]<<endl,exit(0);
			}
		}

	}
   // cout<<1<<endl;
}
原文