Codeforces Round #254 (Div. 2) DZY Loves Chemistry【并查集基础】
一开始不知道题意是啥意思,迟放进去反应和后放进去反应有什么区别
对于第三组数据不是很懂,为啥312,132的组合是不行的
后来发现这是一道考察并查集的题目 QAQ
怒贴代码:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <algorithm>
using namespace std; const int INF = 0x3f3f3f3f; int n, m, fa[], x, y; int gf(int x) {
if (fa[x] != x) fa[x] = gf(fa[x]);
return fa[x];
} int main() {
scanf("%d%d", &n, &m);
for (int i = ; i <= n; i++) fa[i] = i;
while (m--) {
scanf("%d%d", &x, &y);
fa[gf(x)] = gf(y);
}
long long ans = (1LL << n);
for (int i = ; i <= n; i++)
if (gf(i) == i) ans /= ;
printf("%I64d\n", ans);
}
Codeforces Round #254 (Div. 2) DZY Loves Chemistry【并查集基础】的更多相关文章
- [Codeforces Round #254 div1] C.DZY Loves Colors 【线段树】
题目链接:CF Round #254 div1 C 题目分析 这道题目是要实现区间赋值的操作,同时还要根据区间中原先的值修改区间上的属性权值. 如果直接使用普通的线段树区间赋值的方法,当一个节点表示的 ...
- Codeforces Round #245 (Div. 2) B. Balls Game 并查集
B. Balls Game Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/430/problem ...
- Codeforces Round #345 (Div. 1) E. Clockwork Bomb 并查集
E. Clockwork Bomb 题目连接: http://www.codeforces.com/contest/650/problem/E Description My name is James ...
- Codeforces Round #345 (Div. 2) E. Table Compression 并查集
E. Table Compression 题目连接: http://www.codeforces.com/contest/651/problem/E Description Little Petya ...
- Codeforces Round #603 (Div. 2) D. Secret Passwords 并查集
D. Secret Passwords One unknown hacker wants to get the admin's password of AtForces testing system, ...
- Codeforces Round #600 (Div. 2) D题【并查集+思维】
题意:给你n个点,m条边,然后让你使得这个这个图成为一个协和图,需要加几条边.协和图就是,如果两个点之间有一条边,那么左端点与这之间任意一个点之间都要有条边. 思路:通过并查集不断维护连通量的最大编号 ...
- Codeforces Round #345 (Div. 2) E. Table Compression 并查集+智商题
E. Table Compression time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Round #600 (Div. 2) - D. Harmonious Graph(并查集)
题意:对于一张图,如果$a$与$b$连通,则对于任意的$c(a<c<b)$都有$a$与$c$连通,则称该图为和谐图,现在给你一张图,问你最少添加多少条边使图变为和谐图. 思路:将一个连通块 ...
- Codeforces Round #345 (Div. 1) C. Table Compression (并查集)
Little Petya is now fond of data compression algorithms. He has already studied gz, bz, zip algorith ...
随机推荐
- codeforces 628F. Bear and Fair Set 网络流
题目链接 F. Bear and Fair Set time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- python第一步
安装2.7的python 环境:到cmd下python,就可以跑代码了,要是想运行py文件,在命令行python test.py,记得在windows下把python加入环境变量 学习基础的语法: 注 ...
- 未能加载文件或程序集“xxxx”或它的某一个依赖项
一般是解决方案中相互依赖的项目生成的目标平台不一样所致,更改为相同目标即可!
- 解读ECMAScript 6箭头函数
箭头函数是ECMAScript 6最受关注的更新内容之一.它引入了一种用「箭头」(=>)来定义函数的新语法,它…它碉堡了~.箭头函数与传统的JavaScript函数主要区别在于以下几点: 对 t ...
- JAVA GUI学习 - JFileChooser文件选择器组件学习:未包括JFileChooser系统类学习
public class JFileChooserKnow { /** * @param args */ public static void main(String[] args) { // TOD ...
- Flex TextInput的restrict属性应用
1,<mx:TextInput id="test_ti" width="160" maxChars="20" restrict=&qu ...
- beini破解无线
软件介绍 当你的笔记本有无线网卡却不能上网的时刻,也许你会很焦急. 又或许你的隔壁就有无线网络可以接的时刻,但你却由于米有密码而不能上网.下面我将简介一款可以令你惊讶的软件,奶瓶 有了奶瓶以上疑问都可 ...
- Linux相关问题-CentOS6.5 x64版本号下Tomcat无法自启动的解决的方法
前段时间使用阿里云server.使用的是Linux CentOS6.5系统,在搭建完Tomcat后发现,Tomcat无法自启动. 将启动tomcat的命令为tomcat_home/bin/startu ...
- Git基础 1 ---- 版本控制系统的介绍
1 Git 1 版本控制系统 vcs - version control system 2 版本控制是一种记录一个或若干文件内容变化,以便将来查阅特定版本修订情况的系统 3 版本控制系统的主要功能 1 ...
- React Native-目前最火的前端技术?
做为一名产品经理,你是否遇到过这样的窘境,“帮我把字体调成 16号呗,颜色变成 #FFFF00FF,老大说这里最好改一下”,作为一名 app 的开发只能无奈但心里窃喜的告诉你,“只能等下个版本了,必须 ...