这题就是坑人的,因为way我前一半存正图,后一半存反图,导致一般扩大两倍过不了,而是要扩大四倍,就是这个坑!!!!!

 #include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
const int maxn=4e6+;
struct node
{
int val;
int next;
}way[maxn];
queue< int >q;
int n,m;
bool vis[],cover[];
int nex[];
int cnt,head[];
int last[];
int s[],ans;
int tot=;
int add(int x,int y)
{
way[++tot].next=head[x];
way[tot].val=y;
head[x]=tot;
}
void de(int x)
{
nex[last[x]]=nex[x];
last[nex[x]]=last[x];
}
int main()
{
cin>>n>>m;
int x,y;
for(int i=;i<=m;i++)
{
cin>>x>>y;
add(x,y);
add(y,x);
}
//cout<<tot<<endl;
nex[]=;
for(int i=;i<n;i++)
{
last[i+]=i;
nex[i]=i+;
} for(int i=;i<=n;i++)
{
if(!vis[i])
{
s[++ans]=;
vis[i]=true;
q.push(i);
de(i);
// cout<<1111111<<endl;
while(!q.empty())
{
int x=q.front();
q.pop();
for(int j=head[x];j;j=way[j].next)
{
if(!vis[way[j].val])
{
cover[way[j].val]=true;
}
}
for(int j=nex[];j;j=nex[j])
{
if(!cover[j])
{
vis[j]=true;
s[ans]++;
de(j);
q.push(j);
}
else
cover[j]=false;
}
}
}
}
//cout<<1111111<<endl;
sort(s+,s++ans);
cout<<ans<<endl;
for(int i=;i<=ans;i++)
{
cout<<s[i]<<" ";
}
/*cout<<endl<<endl;
for(int i=1;i<=n;i++)
{
cout<<nex[i]<<" ";
}*/
return ;
}

洛谷P3452 [POI2007]BIU-Offices的思考的更多相关文章

  1. [洛谷P3460] [POI2007]TET-Tetris Attack

    洛谷题目链接:[POI2007]TET-Tetris Attack 题目描述 A puzzle called "Tetris Attack" has lately become a ...

  2. [洛谷3457][POI2007]POW-The Flood

    洛谷题目链接:[POI2007]POW-The Flood 题意翻译 Description 你手头有一张该市的地图.这张地图是边长为 m∗n 的矩形,被划分为m∗n个1∗1的小正方形.对于每个小正方 ...

  3. 洛谷P3459 [POI2007]MEG-Megalopolis(树链剖分,Splay)

    洛谷题目传送门 正解是树状数组维护dfn序上的前缀和,这样的思路真是又玄学又令我惊叹( 我太弱啦,根本想不到)Orz各路Dalao 今天考了这道题,数据范围还比洛谷的小,只有\(10^5\)(害我复制 ...

  4. 洛谷P3459 [POI2007]MEG-Megalopolis [树链剖分]

    题目传送门 MEG 题目描述 Byteotia has been eventually touched by globalisation, and so has Byteasar the Postma ...

  5. 洛谷 P3462 [POI2007]ODW-Weights

    题面: https://www.luogu.org/problemnew/show/P3462 https://www.lydsy.com/JudgeOnline/problem.php?id=111 ...

  6. Connected Components? Codeforces - 920E || 洛谷 P3452 &&bzoj1098 [POI2007]BIU-Offices

    https://codeforces.com/contest/920/problem/E https://www.luogu.org/problemnew/show/P3452 https://www ...

  7. 洛谷 P3456 [POI2007]GRZ-Ridges and Valleys

    P3456 [POI2007]GRZ-Ridges and Valleys 题意翻译 给定一个地图,为小朋友想要旅行的区域,地图被分为n*n的网格,每个格子(i,j) 的高度w(i,j)是给定的.若两 ...

  8. 洛谷 P3455 [POI2007]ZAP-Queries (莫比乌斯函数)

    题目链接:P3455 [POI2007]ZAP-Queries 题意 给定 \(a,b,d\),求 \(\sum_{x=1}^{a} \sum_{y=1}^{b}[gcd(x, y) = d]\). ...

  9. 洛谷P3459 [POI2007]MEG-Megalopolis [2017年6月计划 树上问题02]

    [POI2007]MEG-Megalopolis 题目描述 Byteotia has been eventually touched by globalisation, and so has Byte ...

随机推荐

  1. JS中的排序算法-冒泡排序解析

    冒泡排序算法 例子:10,8,9,6,4,20,5  从小到大排序 第一轮  1)10>8  交换数据 得到:8,10,9,6,4,20,5 2)10>9  交换数据 得到:8,9,10, ...

  2. python编程基础之二十三

    集合:和数学里面完全一样的,不允许有重复元素,如果添加重复元素,就会被过滤,可以进行交并差的运算  集合是可变对象 本质:无需且无重复的数据结构 创建集合 s1 = set()  括号里面可以放可迭代 ...

  3. Color Length UVALive - 5841

    题文:见网页:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=sho ...

  4. Android Studio:多包名打包

    来自:http://m.blog.csdn.net/u011315960/article/details/73251196 前言 最近有点小忙,博客都落下了,今天赶紧写点东西补上. 前几天商务找我,想 ...

  5. 最新打赏正版V15微信视频打赏源码 带(百倍)暗雷 N秒试看 自动切换域名 自动防封

    免签支付域名防封随机跳转盒子推广设置试看N秒百倍 平台搭建:乌龟-源码科技QQ:64430146 全新版本 V15打赏版本功能介绍: 特别注意: 新增加功能!!!! 1.包括V14所有功能(除个别因优 ...

  6. MySQL学习(一)索引的基本认识

    MySQL中,所有的数据类型都可以被索引,包括普通索引,唯一性索引,全文索引,单列索引,多列索引和空间索引等. 额外的:我已知的自动创建索引的时机:创建主键,唯一,外键约束的时候 一.索引简介 1.1 ...

  7. Java学习笔记之封装与继承

    封装 1,将属性定义为私有的(private)   不能通过  对象名.属性  来直接访问,但是可以通过方法来间接的访问, 2,封装的意义:公有属性可以被随意修改,并且不能被程序察觉.封装后,别人通过 ...

  8. 常见PHP危险函数及特殊函数

    PHP代码执行函数 - eval & assert & preg_replace mixed eval ( string $code ) 把字符串 $code 作为PHP代码执行. 很 ...

  9. Hadoop实战1:MapR在ubuntu集群中的安装

    由于机器学习算法在处理大数据处理的时候在所难免的会效率降低,公司需要搭建hadoop集群,最后采用了商业版的Hadoop2(MapR). 官网: http://doc.mapr.com/display ...

  10. 抛弃Eclipse,投入IDEA 的独孤求败江湖

    "工欲善其事,必先利其器" 出处:孔子<论语> 两年了,这是我的 IDEA 实用技巧总结,从前我是一个 Eclipse 忠实用户,直到某天我用上了 IntelliJ I ...