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. UVM中的regmodel建模(二)

    UVM的寄存器模型,对一个寄存器bit中有两种数值,mirror值,尽可能的反映DUT中寄存器的值.expected值,尽可能的反映用户期望的值. 几种常用的操作: read/write:可以前门访问 ...

  2. Azkaban 简介

    本文简单介绍一下Azkaban及其特点.azkaban是一个开源的任务调度系统,用于负责任务的调度运行(如数据仓库调度),用以替代linux中的crontab. 一.Azkaban是什么? 1.1 A ...

  3. python 字符串的I/O 操作

    想使用操作类文件对象的程序来操作文本或二进制字符串 使用io.StringIO() 和io.BytesIO() 类来创建类文件对象操作字符串数据 >>> s = io.StringI ...

  4. 用crontab执行shell把top命令按日期追加到文件

    用crontab执行shell把top命令按日期追加到文件 详细图文解说请到本人原创百度经验http://jingyan.baidu.com/article/3052f5a1daf11197f21f8 ...

  5. iphone6 inline-flex兼容问题

    在编写微信端页面时,遇到这样的问题:position属性为flex的导航栏,其li标签在其余设备上显示正常,但在iphone6上浮动错误. 究其原因,是iphone6不支持position属性中的fl ...

  6. echart知识点、常用图形

    原文地址:https://www.cnblogs.com/kewenxin/p/9338272.html 本文是自己在项目中需要运用到的echarts图形进行整理,都有完整的代码.echarts原型, ...

  7. cojs DAG计数问题1-4 题解报告

    最近突然有很多人来问我这些题目怎么做OwO 然而并不是我出的,结论我也不是很懂 研究了一下觉得非常的一颗赛艇,于是就打算写这样一篇题解 DAG 1 我们考虑DAG的性质,枚举出度为0的点 设出度为0的 ...

  8. python脚本监控获取当前Linux操作系统[内存]/[cpu]/[硬盘]/[登录用户]

    此脚本应用在linux, 前提是需要有python和python的psutil模块 脚本 #!/usr/bin/env python # coding=utf-8 import sys import ...

  9. 20145335郝昊《网络攻防》Exp4 Msf基础

    20145335郝昊<网络攻防>Exp4 Msf基础 实验内容 掌握metasploit的基本应用方式,掌握常用的三种攻击方式的思路. 一个主动攻击,如ms08_067; 一个针对浏览器的 ...

  10. 基于Android的闹钟的软件

    一.本课题要求:设计一个基于Android的闹钟的软件. 实现的功能有:能通过界面设置闹钟的启动条件建立后台服务进程,当满足触发条件时,闹钟响应相应事件. 二.需求分析 该课题实现在手机操作系统And ...