洛谷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 ...
随机推荐
- 10个值得深思的_PHP_面试问题
Q1 第一个问题关于弱类型 $str1 = 'yabadabadoo'; $str2 = 'yaba'; if (strpos($str1,$str2)) { echo "\"&q ...
- React 项目引入 Dva
背景 现在手上在做的 React 项目因为年代久远,用的 Redux,写代码的体验不太好,所以想升级一下引入 dva.以往使用 dva 都是使用 dva-cli 直接生成 dva 项目,或者在使用 a ...
- 为什么一个Http Header中的空格会被骇客利用 - HTTP request smuggling
figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...
- 我在用的翻译软件 -> 微软翻译+网易有道词典+谷歌翻译
Windows网页翻译 因为微软翻译相对来说翻译网页更为准确,我也喜欢用谷歌的Chrome浏览器,但是我没找到微软翻译的扩展,这里只能放弃 这个需要配合Microsoft Edge浏览器进行使用,也是 ...
- QR 码详解(下)
快速响应矩阵码(下) 书接上回,继续下半场. 纠错码 QR 码采用纠错算法生成一系列纠错码字,添加在数据码字序列之后,使得符号可以在遇到损坏时可以恢复.这就是为什么二维码即使有残缺也可以扫出来.没有残 ...
- cocos2d-x 系统学习cocos(1)
简析HelloWorld场景 以前使用cocos2d-x 3.14的时候,HelloWorld并不是一个场景类,而是一个图层类,当时的HelloWorld::createScene()是长这样的 Sc ...
- HashMap的结构以及核心源码分析
摘要 对于Java开发人员来说,能够熟练地掌握java的集合类是必须的,本节想要跟大家共同学习一下JDK1.8中HashMap的底层实现与源码分析.HashMap是开发中使用频率最高的用于映射(键值对 ...
- 10月27日Java整理
实验一:凯撒密码 import java.util.Scanner; //zhanxinwu,October,25,2016 public class Addmi { public static vo ...
- Cocos Creator 通用框架设计 —— 资源管理
如果你想使用Cocos Creator制作一些规模稍大的游戏,那么资源管理是必须解决的问题,随着游戏的进行,你可能会发现游戏的内存占用只升不降,哪怕你当前只用到了极少的资源,并且有使用cc.loade ...
- 打造属于自己的 HTML/CSS/JavaScript 实时编辑器
转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者.原文出处:https://blog.bitsrc.io/build-an-html-css-js-playgr ...