1098: [POI2007]办公楼biu
来源:互联网 发布:淘宝怎么上直通车 编辑:程序博客网 时间:2024/04/28 18:07
1098: [POI2007]办公楼biu
Time Limit: 20 Sec Memory Limit: 162 MBSubmit: 1122 Solved: 509
[Submit][Status][Discuss]
Description
FGD开办了一家电话公司。他雇用了N个职员,给了每个职员一部手机。每个职员的手机里都存储有一些同事的
电话号码。由于FGD的公司规模不断扩大,旧的办公楼已经显得十分狭窄,FGD决定将公司迁至一些新的办公楼。FG
D希望职员被安置在尽量多的办公楼当中,这样对于每个职员来说都会有一个相对更好的工作环境。但是,为了联
系方便起见,如果两个职员被安置在两个不同的办公楼之内,他们必须拥有彼此的电话号码。
Input
第一行包含两个整数N(2<=N<=100000)和M(1<=M<=2000000)。职员被依次编号为1,2,……,N.以下M行,每
行包含两个正数A和B(1<=A
Output
包含两行。第一行包含一个数S,表示FGD最多可以将职员安置进的办公楼数。第二行包含S个从小到大排列的
数,每个数后面接一个空格,表示每个办公楼里安排的职员数。
Sample Input
7 16
1 3
1 4
1 5
2 3
3 4
4 5
4 7
4 6
5 6
6 7
2 4
2 7
2 5
3 5
3 7
1 7
1 3
1 4
1 5
2 3
3 4
4 5
4 7
4 6
5 6
6 7
2 4
2 7
2 5
3 5
3 7
1 7
Sample Output
3
1 2 4
1 2 4
HINT
FGD可以将职员4安排进一号办公楼,职员5和职员7安排进2号办公楼,其他人进3号办公楼。
Source
#include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm>#include<cstring>#include<cmath>#include<vector>#include<queue>using namespace std;const int maxn = 1E5 + 10;struct data{int pre,nex;}a[maxn];int n,tot,m,ti,pre[maxn],nex[maxn],ans[maxn],vis[maxn],p[maxn];vector <int> v[maxn];queue <int> q;int main(){#ifdef YZY freopen("yzy.txt","r",stdin);#endifcin >> n >> m;while (m--) {int x,y; scanf("%d%d",&x,&y);v[x].push_back(y); v[y].push_back(x);}for (int i = 1; i <= n; i++) pre[i] = i-1,nex[i] = i+1;nex[0] = 1; pre[n+1] = n; while (nex[0] != n+1) {++tot; ++ans[tot]; q.push(nex[0]); nex[0] = nex[nex[0]]; pre[nex[0]] = 0;while (!q.empty()) {int k = q.front(); q.pop(); ++ti;for (int i = 0; i < v[k].size(); i++) vis[v[k][i]] = ti;for (int x = nex[0]; x != n+1; x = nex[x]) if (vis[x] != ti) {nex[pre[x]] = nex[x];pre[nex[x]] = pre[x];++ans[tot]; q.push(x);} }}printf("%d\n",tot);sort(ans + 1,ans + tot + 1);for (int i = 1; i <= tot; i++) printf("%d ",ans[i]);return 0;}
0 0
- 1098: [POI2007]办公楼biu
- BZOJ 1098: [POI2007]办公楼biu
- BZOJ 1098: [POI2007]办公楼biu
- bzoj 1098: [POI2007]办公楼biu
- bzoj-1098: [POI2007]办公楼biu
- [BZOJ]1098: [POI2007]办公楼biu
- BZOJ 1098: [POI2007]办公楼biu
- BZOJ 1098 [POI2007]办公楼biu 链表
- 1098: [POI2007]办公楼biu 链表+BFS
- 【BZOJ】1098 [POI2007]办公楼biu 链表+BFS
- BZOJ 1098: [POI2007]办公楼biu 链表bfs
- [POI2007]办公楼biu
- 【bzoj1098】 [POI2007]办公楼biu
- [BZOJ1098][POI2007]办公楼biu
- bzoj1098: [POI2007]办公楼biu
- [bzoj1098][POI2007]办公楼biu
- 【bzoj1098】[POI2007]办公楼biu
- 【bzoj1098】 [POI2007]办公楼biu
- 使用ImageLoader实现图片异步加载
- 浅谈C++中指针和引用的区别
- SafeArray使用方法和函数解析
- 用Activity的onTouchEvent方法实现监听手指上下左右滑动
- 【计算机图形学】OpenGL+VS2015相关类库配置
- 1098: [POI2007]办公楼biu
- #Paper Reading# Private traits and attributes are predictable from digital records of human behavior
- Runloop
- Python filter()函数
- 莫比乌斯反演练习bzoj2440;bzoj2301;bzoj2820 YY的GCD
- new start
- Linux搭建SVN客户端
- idea中tomcat部署出问题
- Codeforces Round #356 (Div. 1)