Problem Description
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:

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?

 
Input
There are no more than 100 testcases.

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

.

 
Output
For each testcase, if the tree is special print "YES" , otherwise print "NO".
 
Sample Input
3
1 2
2 3
4
1 2
2 3
1 4
 
Sample Output
YES
NO

Hint

For the second testcase, this tree is similiar with the given tree:
4
1 2
1 4
3 4

 
 
题意就是每层数只能有一个节点(除了最后一层的节点)
多于这种多个数需要记录其中每个数出现的次数的情况  灵活的使用标记数组
#include<string.h>
#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的更多相关文章

  1. HDU 5432 Rikka with Tree (BestCoder Round #53 (div.2))

    http://acm.hdu.edu.cn/showproblem.php?pid=5423 题目大意:给你一个树 判断这棵树是否是独特的 一颗树是独特的条件:不存在一颗和它本身不同但相似的树 两颗树 ...

  2. hdu 5432 Pyramid Split 二分

    Pyramid Split Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/conte ...

  3. HDU 5432 Pyramid Split

    题意:有n个底面是正方形的四棱锥,用一个水平截面将所有四棱锥分成两半,要求上一半体积的和等于下一半,求水平截面的高度,输出整数部分. 解法:二分截面高度.比赛的时候二分写不明白了orz…… 代码: # ...

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

  5. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  6. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  7. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  8. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  9. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

随机推荐

  1. Confluence 实现公司wiki【转】

    Confluence是一个企业级的Wiki软件,可用于在企业.部门.团队内部进行信息共享和协同编辑一.安装过程1 安装并配置mysql [root@vm1 ~]# /etc/my.cnf charac ...

  2. Java 13 特性解读

    Java 13 特性解读    转 https://blog.csdn.net/bjweimengshu/article/details/100978383   2017年8月,JCP执行委员会提出将 ...

  3. [转]浅谈HTTP中GET、POST用法以及它们的区别

    HTTP定义了与服务器交互的不同方法,最基本的方法有4种,分别是GET,POST,PUT,DELETE.URL全称是资源描述符.我们可以这样认为: 一个URL地址,它用于描述一个网络上的资源,而HTT ...

  4. axios请求数据完整

    <template> <!-- 所有的内容要被根节点包含起来 --> <div id="home"> 首页组件 <button @clic ...

  5. SeetaFace2 cmake VS2015编译编译

    cmake Selecting Windows SDK version 10.0.17134.0 to target Windows 10.0.18362. == BUILD_VERSION: v2. ...

  6. 算法习题---5-4交换学生(UVa10763)

    一:题目 有一组学生,他们手中分别有自己学校和想要去的目标学校(A,B).为了成功的交换学生,必须保证这一组学生中必须每两个人之间满足 s1 (A,B) 和 s2 (B,A).即两者原来和目标学校相对 ...

  7. Python - Django - 页面上展示固定的页码数

    如果页数太多的话,全部显示在页面上就会显得很冗杂 可以在页面中显示规定的页码数 例如: book_list.html: <!DOCTYPE html> <html lang=&quo ...

  8. 什么是 https ?这应该是全网把 https 讲的最好的一篇文章了

    https://blog.csdn.net/m0_37907797/article/details/102759257

  9. 使用JSQLParser解析SQL中涉及到的表

    首先添加Maven依赖: <dependency> <groupId>com.github.jsqlparser</groupId> <artifactId& ...

  10. Mac下WordPress4.1安装使用笔记

    WordPress简介         WordPress是一种使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设属于自己的网站.也可以把 WordPress当作一个内 ...