OvO http://codeforces.com/contest/920/problem/E

  模拟一遍……

  1.首先把所有数放到一个集合 s 中,并创建一个队列 que

  2.然后每次随便取一个数,并且从集合中删除这个数,将这个数放入 que

  3.取 que 首元素,记为 now,然后枚举集合 s,每次找到 s 中和 now 相连的元素 x,从 s 中删除元素 x,并且把 x 放入 que 中。

  4.如果 s 不为空,回到步骤2

  可见就是一个模拟,至于复杂度,计算如下。

  由于每个数字只会从集合 s 中删除一次。步骤3中枚举集合 s 元素的操作中,记成功从集合 s 中删除元素的为有效操作,反之为无效操作,则每一次有效操作必然会使 s 中元素数量减,所以有效操作复杂度为O(n)。而每次无效操作则必然会使用到一对题目所给的 (x,y),其中 x 与 y 不相连,可见无效操作复杂度为 O(m)。

  其他复杂度计算显然。加起来不会超时。

  

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <queue> using namespace std; const int M=2e5+;
const int N=2e5; vector<int> mp[M];
queue<int> que;
set<int> s;
int n,m;
int lans,ans[M]; void init()
{
for(int i=;i<=N;i++)
mp[i].clear();
s.clear();
lans=;
} bool isConnected(int a,int b)
{
vector<int>::iterator it=lower_bound(mp[a].begin(),mp[a].end(),b);
if(it==mp[a].end() || *it!=b) return true;
return false;
} void solve()
{
queue<int> dlt;
int now,tmp;
set<int>::iterator it,tmp_it;
for(int i=;i<=n;i++)
s.insert(i);
while(s.size()>)
{
while(!que.empty()) que.pop();
while(!dlt.empty()) dlt.pop();
lans++; ans[lans]=;
it=s.begin(); now=*it;
// cout<<now<<' ';
s.erase(it); ans[lans]++;
que.push(now);
while(!que.empty())
{
now=que.front(); que.pop();
for(it=s.begin();it!=s.end();it++)
if(isConnected(now,*it))
{
// cout<<*it<<' ';
que.push(*it),ans[lans]++,dlt.push(*it);
}
while(!dlt.empty())
{
tmp=dlt.front(); dlt.pop();
s.erase(tmp);
}
}
// cout<<endl;
// cout<<s.size()<<endl;
}
} int main()
{
init();
int a,b;
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++)
{
scanf("%d%d",&a,&b);
mp[a].push_back(b),mp[b].push_back(a);
}
for(int i=;i<=n;i++)
sort(mp[i].begin(),mp[i].end());
solve();
sort(ans+,ans+lans+);
printf("%d\n",lans);
for(int i=;i<=lans;i++)
printf("%d ",ans[i]);
puts("");
return ;
}

最新文章

  1. 逆向分析AHpack
  2. Eclipse 自动补全功能失效解决办法及修改快捷键方法
  3. 九、DAG hierarchy
  4. MySQL添加字段和修改字段的方法
  5. SQL Server面试题
  6. stm32上的Lava虚拟机开发进度汇报(3)
  7. Android 动画效果 及 自定义动画
  8. python-多线程(原理篇)
  9. Javascript 设计模式笔记
  10. CDN架构以及原理分析
  11. 含隐变量模型求解——EM算法
  12. SAP MM 明明已经扩展供应商到采购组织下,采购订单里还是报错?
  13. GIT-windows系统部署gitblit服务器
  14. Git——快速重命名文件和查看commit提交版本【四】
  15. python pip下载速度慢的解决方法
  16. ruby学习-字符串
  17. layer开启与关闭加载层
  18. 用 Django 做了一个照片分享网站
  19. Visual Studio 使用Web Deploy发布项目
  20. 代码规范审查 – Sonar分析项目

热门文章

  1. JAVA支持字符编码读取文件
  2. 将 PDF 论文的公式截图后转成 Word 可编辑公式(23)
  3. IntelliJ Idea基于Maven创建SpringMVC程序
  4. 【数据结构】P1981 表达式求值
  5. 【解决方法】You seem to have the current working directory in your LD_LIBRARY_PATH environment variable.
  6. Qt实现艺术字效果
  7. ggplot2|详解八大基本绘图要素
  8. Https请求被中止: 未能创建 SSL/TLS 安全通道
  9. 常用shell命令积累
  10. Seaborn(一)之风格管理