Educational Codeforces Round 37 (Rated for Div. 2) E. Connected Components? 暴力 + 补图的遍历
传送门
文章目录
- 题意:
- 思路:
题意:
n≤2e5,m≤2e5n\le2e5,m\le2e5n≤2e5,m≤2e5。
思路:
这是题是我上个题的一部分,算是个小知识点,暴力能过。
直接维护一个setsetset,让后遍历所有点,如果当前这个点没有被遍历,那么就放入队列中,扩展出去,每个点最多入队一次,而且边数不会很多,复杂度大约是(n+m)logn(n+m)logn(n+m)logn
// Problem: E. Connected Components?
// Contest: Codeforces - Educational Codeforces Round 37 (Rated for Div. 2)
// URL: https://codeforces.com/problemset/problem/920/E
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid (tr[u].l+tr[u].r>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;int n,m;
int p[N],se[N];
LL rest;
bool st[N];
set<int>v[N],all;
struct Node {int a,b,w,flag; bool operator < (const Node &W) const {return w<W.w;}
}edge[N];int find(int x) {return x==p[x]? x:p[x]=find(p[x]);
}void get_block() {queue<int>q;vector<int>now;for(int i=1;i<=n;i++) {if(!st[i]) {q.push(i); st[i]=1;all.erase(i);while(q.size()) {int u=q.front(); q.pop();now.clear();for(auto x:all) {if(v[u].count(x)) continue;q.push(x); now.pb(x);st[x]=1;int a=find(u),b=find(x);se[a]+=se[b];p[b]=a;rest--;}for(auto x:now) all.erase(x);}}}
}int main()
{// ios::sync_with_stdio(false);
// cin.tie(0);cin>>n>>m;rest=1ll*n*(n-1)/2-m;for(int i=1;i<=n;i++) all.insert(i),p[i]=i;for(int i=1;i<=m;i++) {int a,b; scanf("%d%d",&a,&b);v[a].insert(b); v[b].insert(a);}for(int i=1;i<=n;i++) p[i]=i,se[i]=1;get_block();vector<int>ans;for(int i=1;i<=n;i++) if(i==find(i)) ans.pb(se[i]);sort(ans.begin(),ans.end());printf("%d\n",ans.size());for(auto x:ans) printf("%d ",x);return 0;
}
/**/
Educational Codeforces Round 37 (Rated for Div. 2) E. Connected Components? 暴力 + 补图的遍历相关推荐
- Educational Codeforces Round 37 (Rated for Div. 2) 1
Educational Codeforces Round 37 (Rated for Div. 2) A.Water The Garden 题意:Max想给花园浇水.花园可被视为长度为n的花园床,花园 ...
- Educational Codeforces Round 37 (Rated for Div. 2) G
G. List Of Integers time limit per test 5 seconds memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 37 (Rated for Div. 2)
我的代码应该不会被hack,立个flag A. Water The Garden time limit per test 1 second memory limit per test 256 mega ...
- Educational Codeforces Round 90 (Rated for Div. 2)(A, B, C, D, E)
Educational Codeforces Round 90 (Rated for Div. 2) Donut Shops 思路 分三种情况: a==c/ba == c / ba==c/b这个时候两 ...
- Educational Codeforces Round 126 (Rated for Div. 2)(A-E)
A-Array Balancing 题意:给定两个数组a,b,a数组第i个数可以和b数组的第i个数交换,最终求 a1−a2|+|a2−a3|+⋯+|an−1−an||a1−a2|+|a2−a3|+⋯+ ...
- Educational Codeforces Round 138 (Rated for Div. 2) D
Educational Codeforces Round 138 (Rated for Div. 2) D. Counting Arrays 题意 给定长度为nnn的数组aaa,若gcd(ai,i)= ...
- Educational Codeforces Round 114 (Rated for Div. 2) (A ~ F)全题解
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Educational Codeforces Round 114 (Rated for Div. 2) ...
- Educational Codeforces Round 106 (Rated for Div. 2)(A ~ E)题解(每日训练 Day.16 )
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 Educational Codeforces Round 106 (Rated for Div. ...
- Educational Codeforces Round 89 (Rated for Div. 2)(A, B, C, D)
Educational Codeforces Round 89 (Rated for Div. 2) A. Shovels and Swords 思路 题意非常简单,就是得到最多的物品嘛,我们假定a, ...
最新文章
- Velocity魔法堂系列二:VTL语法详解
- 设计模式学习笔记(十)——Decorator装饰模式
- Python安装模块出错(ImportError: No module named setuptools)解决方法
- 第一次听人用男女关系讲 N(Non-Blocking)I(进)O(出),涨姿势了
- NSIS打包软件使用
- mysql数据库引擎调优
- 基础笔试编程题(jz)
- Android8内测申请,小米 6 安卓 8.0 来了 内测开始招募
- 优秀REST风格 API的设计原则
- 团队-爬虫豆瓣top250项目-模块开发过程
- linux跑程序占用缓存过多释放内存echo 3 > /proc/sys/vm/drop_caches
- JDK1.5新特性介绍
- 研究生开口月薪一万 企业暗示“靠边站”
- 请求到达时先经过过滤器还是拦截器_上海自动卷绕式过滤器价格_康斐净化
- Himall商城LinqHelper帮助类(1)
- 跨越13开启14--猿猿感想
- 算命的理科生——顺口说说算命的事......
- 跨境电商的商品是如何出口的-扬帆际海
- 哈夫曼树(模拟+哈夫曼树+最小WPL)
- 编译原理(龙书)学习笔记 第一章
热门文章
- 争时金融java_Java高并发编程基础之AQS
- 被AI人机疯狂单杀?王者荣耀AI“绝悟”亲测体验
- 三年磨一剑,五次被拒稿,交大博士坚持稿件申诉,终发表学科顶刊
- sql 百分数_SQL经典50题笔记
- 鸿蒙蕴含的哲理,经典别致的人生语录,蕴含哲理,受用一生!
- html li 做瀑布流,js实现瀑布流效果(自动生成新的内容)
- java awt区域_java的awt包中有没有表示区域的类或者方法,可以传递一个Rectangle
- java地图 热力图,腾讯地图数据可视化之热力图
- eval() php,js-eval编码,js-eval解码
- linux yum自动挂载_LINUX6安装YUM仓库和实现开机自动挂载