#includeusing namespace std;#define maxn 100005int d[maxn];int n;int fa[maxn];void init(int x){ for(int i=1; i<=x; i++) fa[i]=i,d[i]=1;}int find_fa(int x){ return fa[x] == x ? x : fa[x] = find_fa(fa[x]);}void join(int x,int y){ int fx=find_fa(x); int fy=find_fa(y); if(fx!=fy) { fa[fx]=fy; d[fy] += d[fx]; }}int main(){ int x,y,mx=0; cin>>n; init(n); for(int i=1;i >x>>y; if(x!=1&&y!=1) { join(x,y); } } for(int i=1;i<=n;i++) if(mx
#include#include #include #include using namespace std;const int MAXN=100005;int vis[MAXN],n;vector vec[MAXN];int DFS(int root){ vis[root]=1; int sum=1; for(int i=0;i >n) { for(int i=1;i >x>>y; vec[x].push_back(y); vec[y].push_back(x); } int sum=0; memset(vis,0,sizeof(vis)); vis[1]=1; for(int i=0;i
#include#define mem(a,b) memset(a,b,sizeof(a))using namespace std;typedef long long ll;const int N=100005;int nxt[N];vector e[N];void get_nxt(string &t){ int i=0,j=-1,len=t.size(); nxt[0]=-1; while(i >n; string s; for(int i=0;i >t[i]; cin>>s; for(int i=0;i
find做法