【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两种颜色的格子; 让你在这个格子 ...
随机推荐
- Android 学习笔记进阶14之像素操作
在我们玩的游戏中我们会经常见到一些图像的特效,比如半透明等效果.要实现这种半透明效果其实并不难,需要我们懂得图像像素的操作. 不要怕,其实在Android中Bitmap为我们提供了操作像素的基本方法. ...
- Typedef和#define之间的区别
Typedef和define都可以用来给对象取一个别名,但是两者却有着很大不同. 1. 首先,二者执行时间不同 关键字typedef在编译阶段有效,由于是在编译阶段,因此typedef有类型检查的功能 ...
- 67.nodejs取参四种方法req.body,req.params,req.param,req.body
转自:http://www.cnblogs.com/jkingdom/p/8065202.html 摘要: nodejs取参四种方法req.body,req.params,req.param,req. ...
- 【习题 8-10 UVA - 1614】Hell on the Markets
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 证明:前i个数一定能凑够1..sum[i]中的所有数字 i=1时显然成立. 现在假设i>=2时结论成立 即前i个数字能凑出1. ...
- 洛谷 P2837 晚餐队列安排
P2837 晚餐队列安排 题目背景 Usaco Feb08 Bronze 题目描述 为了避免餐厅过分拥挤,FJ要求奶牛们分2批就餐.每天晚饭前,奶牛们都会在餐厅前排队入内,按FJ的设想,所有第2批就餐 ...
- BestCoder Round #65 HDOJ5592 ZYB's Premutation(树状数组+二分)
ZYB's Premutation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
- Python-根据成绩分析是否继续深造
案例:该数据集的是一个关于每个学生成绩的数据集,接下来我们对该数据集进行分析,判断学生是否适合继续深造 数据集特征展示 GRE 成绩 (290 to 340) TOEFL 成绩(92 to 120) ...
- ByteUtils
package sort.bing.com; import java.io.ByteArrayOutputStream;import java.io.DataOutputStream;import j ...
- atxserver2安装与使用
atxserver2的使用 1.首先clone atxserver2代码,此时使用pip3 install requirements后执行python main.py 会提示“ [WinError 1 ...
- Relaxation step(Dijkstra's 最短路径算法)
翻译成中文就是"松弛",属于工程优化的范畴: Dijkstra 的单源最短路径算法,有一个重要的步奏,当访问到新的结点 u (加入到集合 S),然后遍历 u 的邻接顶点(Adj), ...