【2000*】【Codeforces Round #518 (Div. 1) [Thanks, Mail.Ru!] B】Multihedgehog
【链接】 我是链接,点我呀:)
【题意】
【题解】
找到度数为1的点。
他们显然是叶子节点。
然后每个叶子节点。
往上进行bfs.
累计他们的父亲节点的儿子的个数。
如果都满足要求那么就继续往上走。
直到不能走。或已经走了k步。
且要求走了k步之后。他们都到了同一个节点。(根节点
这道题。
n=1的时候,认为是无解的。
(因为题目中说"some vertices of degree 1",也就是说必须>= 1.......
【代码】
/*
find each vertex i where du[i]==1
bfs(i) one depth and get y,cnt[y]++;
after that
count the number if different cnt[y] ->CNT (only consider cnt[y]>0
if (CNT!=1) return 0;
set the only cnt value as kk
we can now know that the root has kk children
find the root,(du[root]==kk)
(if there are more than one i such that du[i]==kk,no solution
(if there are no such i,such that du[i]==k,no solution
dfs from root.
if (dep!=k && du[x]==1) return 0;//must have k depth
check if every vertex except the bottom vertext all has kk children
*/
#include <bits/stdc++.h>
#define ll long long
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
using namespace std;
const int N = 1e5;
int n,k;
vector<int> g[N+10];
bool flag[N+10];
vector<int> v,tempv;
int cnt[N+10];
void wujie(){
puts("No");
exit(0);
}
int main(){
#ifdef ccy
freopen("rush.txt","r",stdin);
#endif
scanf("%d%d",&n,&k);
if (n==1){
puts("No");
return 0;
}
rep1(i,1,n-1){
int x,y;
scanf("%d%d",&x,&y);
g[x].push_back(y);
g[y].push_back(x);
}
rep1(i,1,n)
if ((int)g[i].size()==1){
v.push_back(i);
}
rep1(dep,1,k){
/*
for (int x:v){
printf("%d ",x);
}
puts("");*/
rep1(j,0,(int)v.size()-1){
int x = v[j];
int cntup = 0;
rep1(l,0,(int)g[x].size()-1){
int y = g[x][l];
// printf("%d ",y);
if (flag[y]) continue;
cnt[y]++;
cntup++;
}
if (cntup!=1) wujie();
flag[x] = true;
}
// puts("");
v.clear();
rep1(i,1,n){
if (cnt[i]!=0 && cnt[i]<3) wujie();
if (cnt[i]==0) continue;
v.push_back(i);
cnt[i] = 0;
}
}
rep1(i,0,(int)v.size()-1){
if (v[i]!=v[0]) wujie();
}
puts("Yes");
return 0;
}
【2000*】【Codeforces Round #518 (Div. 1) [Thanks, Mail.Ru!] B】Multihedgehog的更多相关文章
- Codeforces Round #518 (Div. 2) [Thanks, Mail.Ru!]
Codeforces Round #518 (Div. 2) [Thanks, Mail.Ru!] https://codeforces.com/contest/1068 A #include< ...
- 【Codeforces Round #518 (Div. 2)】
A:https://www.cnblogs.com/myx12345/p/9847588.html B:https://www.cnblogs.com/myx12345/p/9847590.html ...
- 【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& ...
- 【map离散&容斥】Ghosts @Codeforces Round #478 (Div. 2) D
传送门 题意:给你一条直线的斜率a和截距b,和某一时刻n个在直线上的点的横坐标,以及沿坐标轴方向的速度.问你这些点在(-∞,+∞)的时间内的碰撞次数. solution 设两个点在t时刻相碰,有: x ...
- Codeforces Round #518 (Div. 2) B. LCM gcd+唯一分解定律
题意:给出b 求lcm(a,b)/a 在b从1-1e18有多少个不同得结果 思路lcm*gcd=a*b 转换成 b/gcd(a,b) 也就是看gcd(a,b)有多少个值 可以把b 由唯一分解 ...
- Codeforces Round #518 (Div. 2) B LCM
传送门 https://www.cnblogs.com/violet-acmer/p/10163375.html 题解: 这道题有点意思,有点数学的味道. 根据定义“[a,b] / a”可得这求得是l ...
- Codeforces Round #518 Div. 1没翻车记
A:设f[i][j][0/1]为前i个数第i位为j且第i位未满足/已满足限制的方案数.大力dp前缀和优化即可. #include<iostream> #include<cstdio& ...
- Codeforces Round #518 (Div. 2) D(计数DP)
#include<bits/stdc++.h>using namespace std;const long long mod=998244353;int n;int a[100007];l ...
- Codeforces Round #518 (Div. 1) Computer Game 倍增+矩阵快速幂
接近于死亡的选手没有水平更博客,所以现在每五个月更一篇. 这道题呢,首先如果已经有权限升级了,那么后面肯定全部选的是 \(p_ib_i\) 最高的. 设这个值为 \(M=\max \limits_i ...
随机推荐
- bzoj5130: [Lydsy1712月赛]字符串的周期
这道题很有意思啊. 字符串循环节用KMP(手推一下) 假如是26^12肯定很不滋磁 但是可以发现ABA和BCB和BAB这些都是等价的 那就把最小的拿出来搞再乘个排列数就好了 #include<c ...
- (转)dp动态规划分类详解
dp动态规划分类详解 转自:http://blog.csdn.NET/cc_again/article/details/25866971 动态规划一直是ACM竞赛中的重点,同时又是难点,因为该算法时间 ...
- Java常用类及反射,类加载
1.系统相关类 Java提供了System类和Runtime类来与程序运行的平台进行交互 A.System类代表当前Java程序的运行平台 a. System类是一个final类,该类的所有属性和方法 ...
- es6入门6--数组拓展运算符,Array.from()基本用法
本文只是作为ES6入门第九章学习笔记,在整理知识点的同时,会加入部分个人思考与解答,若想知道更详细的介绍,还请阅读阮一峰大神的ES6入门 一.拓展运算符 ES6中新增了拓展运算(...)三个点,它的作 ...
- LMS、NLMS最优步长理论分析与Speex回声消除可能的改进想法
一.回声消除算法模型 先来分析下自适应回声消除的主要组成部分,大体上可以把回声消除模型分为两个部分 横向滤波器结构 滤波器系数自适应与步长控制 横向滤波器用脉冲响应w(n)[有的地方也称为回声路径]与 ...
- 遍历WPF DataGrid单元格
using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Media; ...
- scrollWidth clientWidth offsetWidth
scrollWidth:对象的实际内容的宽度,不包边线宽度,会随对象中内容超过可视区后而变大. 实际内容+padding 不包括滚动条 边框client ...
- (转)用JS实现表格中隔行显示不同颜色
用JS实现表格中隔行显示不同颜色 第一种: <style> tr{bgColor:expression( this.bgColor=((this.rowIndex)%2==0 )? ...
- jQuery的基本概念与高级编程
年创建的一个年月面世的1.5.2版本.作为一个JavaScript库,jQuery极大程度上解决了浏览器的兼容性问题,能够在IE 6.0 +.FF 2.0 +.Safari 3.0 +.Opera 9 ...
- 学习廖雪峰的Python教程之Python基础
一.缩进 编译器或者解释器就是负责把符合语法的程序代码转换成CPU能够执行的机器码,然后执行. 以#开头的语句是注释,注释是给人看的,可以是任意内容,解释器会忽略掉注释.其他每一行都是一个语句,当语句 ...