Codeforces Round #506 (Div. 3) E

dfs+贪心

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = ;
int n,u,v;
int ans;
vector<int>M[maxn];
int dfs(int cur,int pre)
{
int ret = ;
for(int i=;i<M[cur].size();i++)
{
int nex = M[cur][i];
if(pre == nex)continue;
ret = min(ret,dfs(nex,cur));
}
if(ret == && cur != && pre != )ans++;
return (ret+)%;
}
int main()
{
scanf("%d",&n);
for(int i=;i<n;i++){
scanf("%d%d",&u,&v);
M[u].push_back(v);
M[v].push_back(u);
}
dfs(,);
cout<<ans<<endl;
}

Codeforces Round #506 (Div. 3) E的更多相关文章

  1. Codeforces Round #506 (Div. 3) 题解

    Codeforces Round #506 (Div. 3) 题目总链接:https://codeforces.com/contest/1029 A. Many Equal Substrings 题意 ...

  2. Codeforces Round #506 (Div. 3) D-F

    Codeforces Round #506 (Div. 3) (中等难度) 自己的做题速度大概只尝试了D题,不过TLE D. Concatenated Multiples 题意 数组a[],长度n,给 ...

  3. Codeforces Round #506 (Div. 3)

    题解: div3水的没有什么意思 abc就不说了 d题比较显然的就是用hash 但是不能直接搞 所以我们要枚举他后面那个数的位数 然后用map判断就可以了 刚开始没搞清楚数据范围写了快速乘竟然被hac ...

  4. Codeforces Round #506 (Div. 3) D. Concatenated Multiples

    D. Concatenated Multiples You are given an array aa, consisting of nn positive integers. Let's call ...

  5. Codeforces Round #506 (Div. 3) C. Maximal Intersection

    C. Maximal Intersection time limit per test 3 seconds memory limit per test 256 megabytes input stan ...

  6. Codeforces Round #506 (Div. 3) - D. Concatenated Multiples(思维拼接求是否为k的倍数)

    题意 给你N个数字和一个K,问一共有几种拼接数字的方式使得到的数字是K的倍数,拼接:“234”和“123”拼接得到“234123” 分析: N <= 2e5,简单的暴力O(N^2)枚举肯定超时 ...

  7. 【Codeforces Round #506 (Div. 3) 】

    A:https://www.cnblogs.com/myx12345/p/9844334.html B:https://www.cnblogs.com/myx12345/p/9844368.html ...

  8. Codeforces Round #506 (Div. 3)B.Creating the Contest(dp)

    B. Creating the Contest time limit per test 1 second memory limit per test 256 megabytes input stand ...

  9. Codeforces Round #506 (Div. 3) A-C

    CF比赛题解(简单题) 简单题是指自己在比赛期间做出来了 A. Many Equal Substrings 题意 给个字符串t,构造一个字符串s,使得s中t出现k次;s的长度最短 如t="c ...

随机推荐

  1. 【ABAP系列】SAP LSWM处理时,网络中断,出现错误

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP LSWM处理时,网络中断 ...

  2. System.Web.Script.Serialization的引用

    解决方案: 找到C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0 ==>System.Web.Extensions.d ...

  3. python while 循环打印九九乘法表

    方向一 i = 1 while i <= 9: j = 1 while j <= i print('%d*%d = %2d'%( j,i ,i*j),end='') j += 1 prin ...

  4. 正则表达式从入门到放弃「Java」

    正则表达式能做什么? 正则表达式可以用来搜索.编辑或处理文本. 「都懂它可以处理文本,可到底是怎么回事?」 正则表达式的定义 百度百科:正则表达式是对字符串操作的一种逻辑公式,就是用事先定义好的一些特 ...

  5. Netty之揭开BootStrap 的神秘面纱

    客户端BootStrap: Bootstrap 是Netty 提供的一个便利的工厂类, 我们可以通过它来完成Netty 的客户端或服务器端的Netty 初始化.下面我先来看一个例子, 从客户端和服务器 ...

  6. TCP协议-流量控制

    流量控制是通过滑动窗口来实现控制的.使用了坚持定时器,防止发送失败导致死锁.

  7. Struts2之校验

    ##1.输入校验 错误提示页面 <%@ page language="java" contentType="text/html; charset=UTF-8&quo ...

  8. 利用Spring实现Hello World

    因为最近要做Java Web方面的开发,所以,就像使用Spring来实现一个以前学其他程序时首先做的一个示例"Hello World!"练练手,之前用很多中语言实现过hello w ...

  9. Python入门习题10.河内塔(汉诺塔)问题

    例10 共n个圆盘,a,b,c三根柱子 #汉诺塔问题.py def Hanoi(n): #定义n阶汉诺塔问题移动次数函数 if n == 1: return 1 else: return 2*Hano ...

  10. P3806 【模板】点分治1(题解)(点分治)

    P3806 [模板]点分治1(题解)(点分治) 洛谷题目传送门 #include<iostream> #include<cstdlib> #include<cstdio& ...