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 ...
随机推荐
- Cubieboard 关闭板载led
修改script.bin 找到最后节点[led_para] 修改leds_used = 0 script.bin 一般在系统盘的第一个分区 例如nand就在/dev/nanda sdcard就在/d ...
- mybatis获取插入的语句主键(自增主键)
<insert id="insertUser" parameterType="User"> <selectKey keyProperty=&q ...
- JS声明语句提升与作用域
<!DOCTYPE html><html><head></head><body><script>//-------------- ...
- Windows Azure HDInsight 支持预览版 Hadoop 2.2 群集
Windows Azure HDInsight 支持预览版 Hadoop 2.2 群集 继去年 10 月推出 Windows Azure HDInsight 之后,我们宣布 Windows Az ...
- live555学习经验链接一
live555学习经验链接:http://xingyunbaijunwei.blog.163.com/blog/#m=0&t=1&c=fks_084071082087086069082 ...
- Romantic(裸扩展欧几里德)
Romantic Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- tomcat的集群配置
配置环境需要:1.Apache服务器,下载地址:http://httpd.apache.org/download.cgi#apache22 2.tomcat6.0或者tomcat7.0,(集群中tom ...
- 百度前端技术学院Html&CSS学习资源
Web相关名词通俗解释 https://www.zhihu.com/question/22689579 MDN HTML入门 https://developer.mozilla.org/zh-CN/d ...
- 优酷DEMO
http://v.youku.com/v_show/id_XMTQxOTc4ODA4OA==.html http://v.youku.com/v_show/id_XMTQxOTc5MjU1Mg==.h ...
- JavaSE学习总结第22天_IO流4
- 22.01 数据输入输出流的概述和讲解 操作基本数据类型 public class DataInputStreamextends FilterInputStream implements Da ...