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 ...
随机推荐
- selenium 学习笔记 ---新手学习记录(6) 问题总结(java)
1.查看网页的cookie信息 //查看cookie 登录后的cookie Set<Cookie> setcoke= driver.manage().getCookies(); for(C ...
- GDI+ 中发生一般性错误(在 OutputStream 中保存 PNG 格式图像时遇到的问题)
在将图片以 PNG 格式保存至 Response.OutputStream 时,会碰到如下错误: GDI+ 中发生一般性错误. 原因: 在写 PNG 格式的图像时,指针需要在存储的位置来回移动.而 R ...
- 转: markdown基本语法
Markdown 是一种轻量级标记语言,能将文本换成有效的XHTML(或者HTML)文档,它的目标是实现易读易写,成为一种适用于网络的书写语言. Markdown 语法简洁明了,易于掌握,所以用它来写 ...
- 定时每天备份mysql
http://blog.csdn.net/panning_hu/article/details/9210001 Spring MVC Spring中MVC框架的底层实现 http://blog.csd ...
- 软件包管理_rpm命令管理_yum工具管理_文件归档压缩_源码包管理
rpm命令管理软件 对于挂载的像U盘那种都会在midea目录下,但是会显示在桌面上 安装软件(i:install,v:verbose冗长的,h:human):rpm -ivh xxxx.rpm 安 ...
- Android Studio ADB响应失败解决方法
当启动Android Studio时,如果弹出 adb not responding. you can wait more,or kill "adb.exe" process ma ...
- JSTL与EL(转)
基本使用 <c:forEach items="${deptList}" var="dept"> <div ...
- ajax 中文乱码
ajax 中文乱码 Firefox 正常,IE 有问题是 解决办法 data:{"name":name,"number":number,"card ...
- 2014年去哪儿网笔试题--有两个文件context.txt和words.conf,请尝试将他们合并成为一段文字,并打印出来。
有两个文件context.txt和words.conf,请尝试将他们合并成为一段文字,并打印出来. 这两个文件内容如下: context.txt “并不是每个人都需要$(qunar)自己的粮食,$(f ...
- Java-多线程的实现与启动
class mythread extends Thread //多线程的启动 { private String name; public mythread(String name) { t ...