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的更多相关文章

  1. CodeForces - 862B Mahmoud and Ehab and the bipartiteness(二分图染色)

    题意:给定一个n个点的树,该树同时也是一个二分图,问最多能添加多少条边,使添加后的图也是一个二分图. 分析: 1.通过二分图染色,将树中所有节点分成两个集合,大小分别为cnt1和cnt2. 2.两个集 ...

  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 ...

  3. Codeforces 959D. Mahmoud and Ehab and another array construction task(构造, 简单数论)

    Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列 ...

  4. 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 ...

  5. 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 ...

  6. Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)

    Mahmoud and Ehab and yet another xor task 存在的元素的方案数都是一样的, 啊, 我好菜啊. 离线之后用线性基取check存不存在,然后计算答案. #inclu ...

  7. Codeforces 862C - Mahmoud and Ehab and the xor

    862C - Mahmoud and Ehab and the xor 思路:找两对异或后等于(1<<17-1)的数(相当于加起来等于1<<17-1),两个再异或一下就变成0了 ...

  8. Codeforces 862D. Mahmoud and Ehab and the binary string (二分)

    题目链接:Mahmoud and Ehab and the binary string 题意: 一道交互题,首先给出一个字符串的长度l.现在让你进行提问(最多15次),每次提问提出一个字符串,会返回这 ...

  9. CF862B Mahmoud and Ehab and the bipartiteness 二分图染色判定

    \(\color{#0066ff}{题目描述}\) 给出n个点,n-1条边,求再最多再添加多少边使得二分图的性质成立 \(\color{#0066ff}{输入格式}\) The first line ...

随机推荐

  1. c#中WMI 中的日期和时间转为本地时间

    取得的值:CreationDate:20170122084915 .713600+480 转:   var objQuery = new ObjectQuery("select * from ...

  2. PowerDesigner逆向操作(从mysql5.0生成数据库的物理模型),把Comment写到name中,pdm文件导出为word

    PowerDesigner逆向操作(从mysql5.0生成数据库的物理模型) 环境:powderdesigner12.5:mysql5.0步骤:1. 为指定的数据库配置mysql的ODBC数据源先下载 ...

  3. java copy 文件夹

    import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io ...

  4. MySQL数据库----表与表之间的关系

    表1 foreign key 表2 则表1的多条记录对应表2的一条记录,即多对一 利用foreign key的原理我们可以制作两张表的多对多,一对一关系 多对多: 表1的多条记录可以对应表2的一条记录 ...

  5. python模块-random随机数模块

    导入随机数模块import random 1.random.random() 生成[0,1)之间的随机小数 2.random.randint(a,b) 生成[a,b]之间的随机整数 3.random. ...

  6. 20145313张雪纯exp7

    问题 (1)通常在什么场景下容易受到DNS spoof攻击 处于局域网中的时候,例如连接了学校/公司/餐厅wifi. (2)在日常生活工作中如何防范以上两攻击方法 不要轻易点开未知网址.鼠标在链接处停 ...

  7. Cron表达式详解和表达式的验证

    本篇不算原创,因为主要内容来自网上的博客,所以给出我参考文章的链接. 本文cron表达式详解的大部分内容参考了[cron表达式详解]和Quartz使用总结.Cron表达式 这两篇文章. cron校验的 ...

  8. 搭建最新版本的Android开发环境

    只为成功找方法,不为失败找借口! Android开发学习总结(一)——搭建最新版本的Android开发环境 最近由于工作中要负责开发一款Android的App,之前都是做JavaWeb的开发,Andr ...

  9. 三羊献瑞|2015年蓝桥杯B组题解析第三题-fishers

    三羊献瑞 观察下面的加法算式: 祥 瑞 生 辉 三 羊 献 瑞 三 羊 生 瑞 气 (如果有对齐问题,可以参看[图1.jpg]) 其中,相同的汉字代表相同的数字,不同的汉字代表不同的数字. 请你填写& ...

  10. 【安装】Microsoft SQL Server的安装

    数据库版本:2012 系统环境:windows 7 一.安装 依次选择“安装->全新 SQL Server 独立安装或向现有安装添加功能”;点“确定” 选择版本,推荐标准版,这里是直接输入序列号 ...