【Codeforces Round #435 (Div. 2) B】Mahmoud and Ehab and the bipartiteness
【链接】h在这里写链接
【题意】
【题解】
【错的次数】
【反思】
【代码】
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5; vector <int> G[N + 10];
int n,color[N+10],cnt[2]; void dfs(int x, int tmp) {
color[x] = tmp;
cnt[tmp]++;
for (int y : G[x]) {
if (color[y] == -1)
dfs(y, 1 - tmp);
}
} int main() {
//freopen("F:\\rush.txt", "r", stdin);
ios::sync_with_stdio(0), cin.tie(0);
cin >> n;
for (int i = 1; i <= n - 1; i++) {
int x, y;
cin >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
memset(color, 255, sizeof color);
dfs(1, 0);
long long ans = 0;
for (int i = 1;i <= n;i++)
if (color[i] == 1) {
ans += cnt[0] - (int)G[i].size();
}
cout << ans << endl;
return 0;
}
【Codeforces Round #435 (Div. 2) B】Mahmoud and Ehab and the bipartiteness的更多相关文章
- 【Codeforces Round #435 (Div. 2) A】Mahmoud and Ehab and the MEX
		
[链接]h在这里写链接 [题意] 在这里写题意 [题解] 让x没有出现,以及0..x-1都出现就可以了. [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/std ...
 - 【Codeforces Round #435 (Div. 2) C】Mahmoud and Ehab and the xor
		
[链接]h在这里写链接 [题意] 让你组成一个n个数的集合,使得这n个数的异或和为x; x<=1e5 每个数最大1e6; [题解] 1e5<=2^17<=2^18<=1e6的 ...
 - 【Codeforces Round #435 (Div. 2) A B C D】
		
CF比赛题目地址:http://codeforces.com/contest/862 A. Mahmoud and Ehab and the MEX ·英文题,述大意: 输入n,x(n,x& ...
 - 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
		
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
 - 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
		
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
 - 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
		
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
 - 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
		
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
 - 【Codeforces Round #423 (Div. 2) C】String Reconstruction
		
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...
 - 【Codeforces Round #423 (Div. 2) B】Black Square
		
[Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...
 
随机推荐
- findFocus-获得拥有焦点的控件
			
所有的view控件有一个findFocus方法,这个方法如下 /** * Find the view in the hierarchy rooted at this view that current ...
 - button-xml 中android:clickable="false" 属性
			
今天在做项目的时候,遇到了一个问题,就是需要把一个常按监听事件,加到一个linearlayout中,但是,这个linearlayout中有其他的button.textview等控件,这样就导致当我们常 ...
 - Linux集群的I/O性能测试
			
Linux集群的I/O性能测试 本文介绍利用iozone的性能测试工具,来测试集群性能.测试步骤如下:1.在Server节点上安装iozone(可以到www.iozone.org上下载) #rpm ...
 - go 可以开发桌面应用
			
go 可以开发桌面应用 go 可以开发桌面应用,但并不是很舒适.可以使用的GUI库有:1.goqt,LiteIDE作者出品,Go和QT的绑定,还未发布2.go.uik,纯Go实现的并发UI工具3.wa ...
 - java体系学习
			
前端部分: 1)HTML:网页的核心语言,构成网页的基础 2)CSS:使网页更加丰富多彩灿烂的利器 3)JavaScript:使网页动起来的根本,加强了网页和用户之间的交互 4)HTML DOM:换一 ...
 - runlevel---当前Linux系统的运行等级
			
Linux系统有7个运行级别(runlevel)运行级别0:系统停机状态,系统默认运行级别不能设为0,否则不能正常启动运行级别1:单用户工作状态,root权限,用于系统维护,禁止远程登陆运行级别2:多 ...
 - 云服务器查看外网ip
			
curl ip.6655.com/ip.aspx curl whatismyip.akamai.com wget -qO - ifconfig.co curl icanhazip.com dig +s ...
 - Java中join和yield的作用
			
本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 1. A.join,在API中的解释是,堵塞当前线程B,直到A执行完毕并死掉,再执行B. 用一个 ...
 - iOS 基于第三方QQ授权登录
			
基于iOS实现APP的第三方QQ登陆.接入第三方SDK时的一个主要的步骤: 1,找到相关的开放平台.QQ互联平台,http://connect.qq.com/: 2,注冊成功后创建自己的APP.填写一 ...
 - svn: Can't convert string from 'UTF-8' to native encoding 解决的方法
			
今天在down代码时遇到了例如以下问题: [xxx@xxx ~]$ svn co https://xxxxxxxxxxxxx svn: Can't convert string from 'UTF-8 ...