bzoj 1098
来源:互联网 发布:清除网页上的淘宝广告 编辑:程序博客网 时间:2024/05/29 05:56
求 补图的连通块个数
补图炸空间QAQ
链表优化 水过
#include <bits/stdc++.h>using namespace std;typedef long long LL;const int INF = 0x3f3f3f3f;inline int read(void){ int x = 0, c = 0, f = 1; for(;c<'0'||c>'9';c=getchar())f=c!='-'; for(;c>='0'&&c<='9';c=getchar())x=x*10+c-'0'; return f ? x : -x;}const int N = 101000;vector<int> G[N];int n, m, nxt[N], pre[N], ans[N], cnt;bool vis[N];inline void delt(int x) { vis[x] = 1; pre[nxt[x]] = pre[x]; nxt[pre[x]] = nxt[x];}bool vt[N];void bfs(int x) { queue<int> Q; Q.push(x); delt(x); while (!Q.empty()) { int now = Q.front(); Q.pop(); ans[cnt]++; for (vector<int>::iterator i=G[now].begin();i!=G[now].end();i++) vt[*i] = 1; for (int i = nxt[0]; i; i = nxt[i]) { if (!vis[i] && !vt[i]) Q.push(i),delt(i); } for (vector<int>::iterator i=G[now].begin();i!=G[now].end();i++) vt[*i] = 0; }}int main() { n = read(), m = read(); for (int i = 0; i < n; i++) nxt[i] = i + 1; for (int i = 1; i <= n; i++) pre[i] = i - 1; for (int i = 1, u, v; i <= m; i++) { u = read(), v = read(); G[u].push_back(v), G[v].push_back(u); } for (int i = 1; i <= n; i++) if (!vis[i]) cnt++, bfs(i); printf("%d\n",cnt); sort(ans+1,ans+cnt+1); for (int i = 1; i <= cnt; i++) printf("%d ",ans[i]);}
阅读全文
1 1
- bzoj 1098
- bzoj 1098
- bzoj-1098 办公楼biu
- [BZOJ ]
- BZOJ****-****
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- BZOJ
- bzoj
- bzoj
- BZOJ
- SVN/SSH命令行
- String的ReplaceAll方法
- windows系统下端口被占用解决方法
- Error inflating class com.jd.jrapp.widget.swiperefresh.SwipeRefreshListview
- Flutter进阶—网络和HTTP
- bzoj 1098
- AndroidStudio那些常用的配置
- ES6项目构建
- 加密认证程序,保护对象和存储介质,地点
- 拿起鼠标就画原型?交互设计师大咖告诉你该怎么做
- JAVA中线程同步的方法(7种)总结
- JAVA中I/0设计模式
- php打印前一天时间格式
- 在Eclipse 中下载 开源中国码云上的项目