hdu 5432
For a tree T
, let F(T,i)
be the distance between vertice 1 and vertice i
.(The length of each edge is 1).
Two trees A
and B
are similiar if and only if the have same number of vertices and for each i
meet F(A,i)=F(B,i)
.
Two trees A
and B
are different if and only if they have different numbers of vertices or there exist an number i
which vertice i
have different fathers in tree A
and tree B
when vertice 1 is root.
Tree A
is special if and only if there doesn't exist an tree B
which A
and B
are different and A
and B
are similiar.
Now he wants to know if a tree is special.
It is too difficult for Rikka. Can you help her?
For each testcase, the first line contains a number n(1≤n≤1000)
.
Then n−1
lines follow. Each line contains two numbers u,v(1≤u,v≤n)
, which means there is an edge between u
and v
.
1 2
2 3
4
1 2
2 3
1 4
NO
For the second testcase, this tree is similiar with the given tree:
4
1 2
1 4
3 4
#include<queue>
#include<iostream>
using namespace std;
struct node
{
int x,y;
}stu;
int main()
{
int num[1001],ans[1001];
int i,j,t,x,y;
while(cin>>t)
{
queue<node>q;
node tt;
memset(num,0,sizeof(num));
memset(ans,0,sizeof(ans));
num[1]=1;
for(j=1;j<t;j++)
{
cin>>stu.x>>stu.y;
if(num[stu.x]!=0)
{
num[stu.y]=num[stu.x]+1;
continue;
}
if(num[stu.y]!=0)
{
num[stu.x]=num[stu.y]+1;
continue;
}
if(num[stu.x]==0&&num[stu.y]==0)
{
q.push(stu);
continue;
}
}
while(!q.empty())
{
tt=q.front();
q.pop();
if(num[tt.x]!=0)
{
num[tt.y]=num[tt.x]+1;
continue;
}
if(num[tt.y]!=0)
{
num[tt.x]=num[tt.y]+1;
continue;
}
if(num[tt.x]==0&&num[tt.y]==0)
{
q.push(tt);
continue;
}
}
int maxx=0;
for(i=1;i<=t;i++)
{
ans[num[i]]++;
// cout<<ans[num[i]]<<endl;
if(maxx<num[i]) maxx=num[i];
}
int flag=1;
for(j=maxx-1;j>=1;j--)
{
// cout<<ans[j]<<endl;
if(ans[j]>1)
{
flag=0;
break;
}
}
if(flag==0) cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
return 0;
}
hdu 5432的更多相关文章
- HDU 5432 Rikka with Tree (BestCoder Round #53 (div.2))
http://acm.hdu.edu.cn/showproblem.php?pid=5423 题目大意:给你一个树 判断这棵树是否是独特的 一颗树是独特的条件:不存在一颗和它本身不同但相似的树 两颗树 ...
- hdu 5432 Pyramid Split 二分
Pyramid Split Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/conte ...
- HDU 5432 Pyramid Split
题意:有n个底面是正方形的四棱锥,用一个水平截面将所有四棱锥分成两半,要求上一半体积的和等于下一半,求水平截面的高度,输出整数部分. 解法:二分截面高度.比赛的时候二分写不明白了orz…… 代码: # ...
- hdu 5432 Pyramid Split(二分搜索)
Problem Description Xiao Ming is a citizen who's good at playing,he has lot's of gold cones which ha ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
随机推荐
- Win10 剪贴板 快捷键是什么?
使用基于云的剪贴板从一台电脑上复制图像和文本并粘贴到另一台电脑上.你不仅可以从剪贴板历史记录中粘贴,还可以固定你发现自己经常使用的项目. 若要随时访问剪贴板历史记录,请按 Windows 徽标键 ...
- 前端通用下载文件方法(兼容IE)
之前在网上看到一个博主写的前端通用的下载文件的方法,个人觉得很实用,所以mark一下,方便以后查阅 源文地址(源文还有上传/下载excel文件方法) 因为项目要求要兼容IE浏览器,所以完善了一下之前博 ...
- 小D课堂 - 零基础入门SpringBoot2.X到实战_第三节SpringBoot热部署devtool和配置文件自动注入实战_14、SpringBoot2.x使用Dev-tool热部署
学习笔记 热部署 每次修改了代码都需要关闭应用重启 热部署就是有一个插件会监听我们应用的代码文件是否有变化,如果有变化就会有其他的类加载器加载 主要的依赖 复制到我们的pom.xml里面 安装完成ja ...
- ZingChart line 折线图表数据设置
根据 x 坐标和 y 坐标一一对应进行设置 (x,y) { "type": "line", "series":[ {,],[,],[,],[ ...
- netty5服务端检测心跳超时断连
客户端每5秒发送一次心跳给服务端,服务端记录最后一次心跳时间,通过定时任务每10秒检测一下,如果当前时间与最后一次收到的心跳时间之差超过某个阈值,断开与客户端的连接.基于之前的例子(netty5心跳与 ...
- 使用Maven完成SSM框架整合环境构建——基于Spring4和Mybatis3
只言片语 使用Maven来搭建一个SSM环境,其实和使用手工倒入jar的过程没有多大区别,所用的jar包都是一样的,但是区别在与不用你手动导入jar包了,而是只修改pom.xml,maven会自动根据 ...
- Chrome V75V76新版无法存为mhtml格式解决办法
升级到75.76版本后谷歌浏览器Chrome V75.0.3770.142 V76.0.3809.87新版,发现无法另存为/保存网页为MHTML了.原来chrome搞了个"Chrome Fl ...
- 【432】COMP9024,Exercise9
eulerianCycle.c What determines whether a graph is Eulerian or not? Write a C program that reads a g ...
- SqlServer里,一条sql进行递归删除
Server 2005中提供了公用表表达式(CTE),使用CTE,可以使SQL语句的可维护性,同时,CTE要比表变量的效率高得多. 存储过程方法: create proc up_delete_ncla ...
- webpack的配置 @3.6.0
1.下载对应版本的webpack npm install webpack@3.6.0 -save --dev 2.新建webpack.config.js文件,目录结构↑ 3. >>webp ...