Codeforces Round #254(div2)B
就是看无向图有几个连通块,答案就是2n-num。
范围很小,就用矩阵来存图减少代码量。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
using namespace std;
#define INF 1000000000
#define eps 1e-8
#define pii pair<int,int>
#define LL long long int
int n,m,maps[][],a,b;
int mark[],num;
void dfs(int x)
{
mark[x]=;
for(int i=;i<=n;i++)
{
if(mark[i]==&&maps[x][i])
{
dfs(i);
}
}
}
int main()
{
//freopen("in1.txt","r",stdin);
//freopen("out.txt","w",stdout);
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++)
{
scanf("%d%d",&a,&b);
maps[a][b]=maps[b][a]=;
}
for(int i=;i<=n;i++)
{
if(!mark[i])
{
num++;
dfs(i);
}
}
printf("%I64d\n",(LL)<<(n-num));
//fclose(stdin);
//fclose(stdout);
return ;
}
Codeforces Round #254(div2)B的更多相关文章
- Codeforces Round #254(div2)A
很有趣的题.想到了就非常简单,想不到就麻烦了. 其实就是一种逆向思维:最后结果肯定是这样子: WBWBWBWB... BWBWBWBW... WBWBWBWB... ... 里面有“-”的地方改成“- ...
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- 【前行】◇第3站◇ Codeforces Round #512 Div2
[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...
- Codeforces Round 254 (Div. 2)
layout: post title: Codeforces Round 254 (Div. 2) author: "luowentaoaa" catalog: true tags ...
- Codeforces Round#320 Div2 解题报告
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...
- Codeforces Round #564(div2)
Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...
- Codeforces Round #361 div2
ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...
- [Codeforces Round #254 div1] C.DZY Loves Colors 【线段树】
题目链接:CF Round #254 div1 C 题目分析 这道题目是要实现区间赋值的操作,同时还要根据区间中原先的值修改区间上的属性权值. 如果直接使用普通的线段树区间赋值的方法,当一个节点表示的 ...
- Codeforces Round #626 Div2 D,E
比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...
随机推荐
- PAT 天梯赛 L1-046. 整除光棍 【模拟除法】
题目链接 https://www.patest.cn/contests/gplt/L1-046 思路 用同余定理以及模拟除法. AC代码 #include <iostream> #incl ...
- C# 二进制序列化(BinaryFormatter),Xml序列化(XmlSerializer),自己模拟写一个Xml序列化过程。
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- Objective-C系列总结之基础知识
//第一个程序示例 #import <Foundation/Foundation.h> int main(int argc,const char * argv[]) { @autorele ...
- MySQL修改管理员账户密码
报错提示:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)MySQL代理报错提示: ...
- 大数据架构之:Spark
Spark是UC Berkeley AMP 实验室基于map reduce算法实现的分布式计算框架,输出和结果保存在内存中,不需要频繁读写HDFS,数据处理效率更高Spark适用于近线或准实时.数据挖 ...
- /usr/lib/update-notifier/updates-available
/usrb/update-notifier/update-motd-updates-available: 49: /usrb/update-notifier/update-motd-updates- ...
- JSP笔记01——尝试
JSP ————> servlet 我的第1个Java Web应用程序——index.jsp 我的第2个Java Web应用程序——welcome-file 我的第3个Java Web应用程序— ...
- 如何理解Java程序使用Unicode字符集编写
Java采用UTF-16编码作为内码,也就是说在JVM内部,文本是用16位码元序列表示的,常用的文本就是字符(char)和字符串(String)字面常量的内容.注:UTF-16是Unicode字符集的 ...
- linux基础三---网络基础&软件包管理
一 ifconfig:显示所有正在启动的网卡的详细信息或设定系统中网卡的IP地址. ifconfig eno16777736 down/up 关闭/开启 eno16777736 网卡 ifconf ...
- P3413 SAC#1 - 萌数
题目 洛谷 数位动规用爆搜真好玩 做法 含有回文串实际我们仅需判断是否有\(2/3\)回文串 \(Dfs(now,num,pre,ly,lead,prel,top)\): 在第\(now\)位 \(n ...