标签:cto bool for https main span pop set class
题面
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); }
标签:cto bool for https main span pop set class
原文地址:https://www.cnblogs.com/shxnb666/p/11279839.html