TJOI2007小朋友
Posted shxnb666
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TJOI2007小朋友相关的知识,希望对你有一定的参考价值。
题面
https://www.luogu.org/problem/P3852
题解
// luogu-judger-enable-o2 #include<cstdio> #include<cstring> #include<iostream> #include<vector> #define ri register int #define N 10500 using namespace std; inline int read() int ret=0,f=0; char ch=getchar(); while (ch<‘0‘ || ch>‘9‘) f|=(ch==‘-‘),ch=getchar(); while (ch>=‘0‘&& ch<=‘9‘) ret*=10,ret+=(ch-‘0‘),ch=getchar(); return f?-ret:ret; int n,m,s[N]; vector<int> to[N],V[N]; bool vis[N]; int a[N]; int col[N]; int main() n=read(); m=read(); for (ri i=1;i<=m;i++) int a=read(),b=read(); to[a].push_back(b); to[b].push_back(a); for (ri i=1;i<=n;i++) V[0].push_back(i); int x=n; vis[n]=1; int maxs=0; for (ri i=1;i<=n;i++) a[n-i+1]=i; vis[x]=1; for (ri j=0;j<to[x].size();j++) int y=to[x][j]; if (vis[y]) continue; V[++s[y]].push_back(y); if (s[y]>maxs) maxs=s[y]; bool fl=0; while (maxs>=0) for (ri j=V[maxs].size()-1;j>=0;j--) if (vis[V[maxs][j]]) V[maxs].pop_back(); else x=V[maxs][j]; fl=1; break; if (!fl) maxs--; else break; memset(vis,0,sizeof(vis)); int cnt=0; for (ri i=1;i<=n;i++) int x=a[i]; if (vis[x]) continue; cnt++; for (ri i=0;i<to[x].size();i++) int y=to[x][i]; vis[y]=1; printf("%d\n",cnt);
以上是关于TJOI2007小朋友的主要内容,如果未能解决你的问题,请参考以下文章