Codeforces 862B - Mahmoud and Ehab and the bipartiteness
862B - Mahmoud and Ehab and the bipartiteness
思路:先染色,然后找一种颜色dfs遍历每一个点求答案。
代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a)) const int N=1e6+;
bool color[N];
vector<int>g[N];
int c=;
int n;
ll ans=; void dfs(int u,int v)
{
color[v]=!color[u];
if(color[v]==true)c++;
for(int i=;i<g[v].size();i++)
if(g[v][i]!=u)dfs(v,g[v][i]);
} void DFS(int u,int v)
{
if(color[v]==true)ans+=(n-c-g[v].size());
for(int i=;i<g[v].size();i++)
{
if(g[v][i]!=u)DFS(v,g[v][i]);
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
int u,v;
cin>>n;
for(int i=;i<n-;i++)
{
cin>>u>>v;
g[u].pb(v);
g[v].pb(u);
} color[]=false;
dfs(,);
DFS(,);
cout<<ans<<endl; return ;
}
Codeforces 862B - Mahmoud and Ehab and the bipartiteness的更多相关文章
- CodeForces - 862B Mahmoud and Ehab and the bipartiteness(二分图染色)
题意:给定一个n个点的树,该树同时也是一个二分图,问最多能添加多少条边,使添加后的图也是一个二分图. 分析: 1.通过二分图染色,将树中所有节点分成两个集合,大小分别为cnt1和cnt2. 2.两个集 ...
- Coderfroces 862 B . Mahmoud and Ehab and the bipartiteness
Mahmoud and Ehab and the bipartiteness Mahmoud and Ehab continue their adventures! As everybody in ...
- Codeforces 959D. Mahmoud and Ehab and another array construction task(构造, 简单数论)
Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列 ...
- E - Mahmoud and Ehab and the bipartiteness CodeForces - 862B (dfs黑白染色)
Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipa ...
- Codeforces 862A Mahmoud and Ehab and the MEX
传送门:CF-862A A. Mahmoud and Ehab and the MEX time limit per test 2 seconds memory limit per test 256 ...
- Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)
Mahmoud and Ehab and yet another xor task 存在的元素的方案数都是一样的, 啊, 我好菜啊. 离线之后用线性基取check存不存在,然后计算答案. #inclu ...
- Codeforces 862C - Mahmoud and Ehab and the xor
862C - Mahmoud and Ehab and the xor 思路:找两对异或后等于(1<<17-1)的数(相当于加起来等于1<<17-1),两个再异或一下就变成0了 ...
- Codeforces 862D. Mahmoud and Ehab and the binary string (二分)
题目链接:Mahmoud and Ehab and the binary string 题意: 一道交互题,首先给出一个字符串的长度l.现在让你进行提问(最多15次),每次提问提出一个字符串,会返回这 ...
- CF862B Mahmoud and Ehab and the bipartiteness 二分图染色判定
\(\color{#0066ff}{题目描述}\) 给出n个点,n-1条边,求再最多再添加多少边使得二分图的性质成立 \(\color{#0066ff}{输入格式}\) The first line ...
随机推荐
- ShuffleElements(随机打乱数组中的元素)
给定一个数组,随机打乱数组中的元素,题意很简单直接上代码: package Array; import java.util.Arrays; import java.util.Collections; ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON LocalMin1
zw版[转发·台湾nvp系列Delphi例程]HALCON LocalMin1 zw版[转发·台湾nvp系列Delphi例程]HALCON LocalMin1 procedure TForm1.But ...
- Impala和Hive的关系(详解)
Impala和Hive的关系 Impala是基于Hive的大数据实时分析查询引擎,直接使用Hive的元数据库Metadata,意味着impala元数据都存储在Hive的metastore中.并且im ...
- [转] Matlab编程规范(MATLAB Programming Style Guidelines)
转自: Jerry Zitao Liu的博客 主要是参考了下面这篇文章,简洁总结在这里. MATLAB Programming Style Guidelines 简洁总结如下: 表示object的数量 ...
- Python: 正则表达式中的group()
正则表达式中,group()用来提出分组截获的字符串,()用来分组 eg:
- Azkaban-开源任务调度程序(安装篇)
最近项目迁移到新集群,试试同事推荐的开源任务调度程序-azkaban(阿兹卡班),没看错,就是哈利波特里的阿兹卡班,azikaban主要用来解决hadoop依赖任务的执行,但是它本身支持linux和j ...
- mysql 替换函数replace()实现mysql 替换字符串
mysql 替换字符串的实现方法:mysql中replace函数直接替换mysql数据库中某字段中的特定字符串,不再需要自己写函数去替换,用起来非常的方便,mysql 替换函数replace()Upd ...
- iOS开发之AFNetworking实现数据传输和文件上传
//传输数据 1 AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.r ...
- sp3485推荐电路(转)
源: sp3485推荐电路 注意:转自电子发烧友 转:485通信自动收发电路 转: RS485收发的3种典型电路-重点-自动收发电路
- Python Web学习笔记之TCP的3次握手与4次挥手过程
前言 尽管TCP和UDP都使用相同的网络层(IP),TCP却向应用层提供与UDP完全不同的服务.TCP提供一种面向连接的.可靠的字节流服务. 面向连接意味着两个使用TCP的应用(通常是一个客户和一个服 ...