zoukankan      html  css  js  c++  java
  • hdu 5977 Garden of Eden

    Garden of Eden

    Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
    Total Submission(s): 581    Accepted Submission(s): 164


    Problem Description
    When God made the first man, he put him on a beautiful garden, the Garden of Eden. Here Adam lived with all animals. God gave Adam eternal life. But Adam was lonely in the garden, so God made Eve. When Adam was asleep one night, God took a rib from him and made Eve beside him. God said to them, “here in the Garden, you can do everything, but you cannot eat apples from the tree of knowledge.”
    One day, Satan came to the garden. He changed into a snake and went to live in the tree of knowledge. When Eve came near the tree someday, the snake called her. He gave her an apple and persuaded her to eat it. Eve took a bite, and then she took the apple to Adam. And Adam ate it, too. Finally, they were driven out by God and began a hard journey of life.
    The above is the story we are familiar with. But we imagine that Satan love knowledge more than doing bad things. In Garden of Eden, the tree of knowledge has n apples, and there are k varieties of apples on the tree. Satan wants to eat all kinds of apple to gets all kinds of knowledge.So he chooses a starting point in the tree,and starts walking along the edges of tree,and finally stops at a point in the tree(starting point and end point may be same).The same point can only be passed once.He wants to know how many different kinds of schemes he can choose to eat all kinds of apple. Two schemes are different when their starting points are different or ending points are different.
     
    Input
    There are several cases.Process till end of input.
    For each case, the first line contains two integers n and k, denoting the number of apples on the tree and number of kinds of apple on the tree respectively.
    The second line contains n integers meaning the type of the i-th apple. Types are represented by integers between 1 and k .
    Each of the following n-1 lines contains two integers u and v,meaning there is one edge between u and v.1≤n≤50000, 1≤k≤10
     
    Output
    For each case output your answer on a single line.
     
    Sample Input
    3 2 1 2 2 1 2 1 3
     
    Sample Output
    6
     
    Source
     
    Recommend
     
     
     
  • 相关阅读:
    centos6.5 升级安装pcre 8.39版本
    解决MongoDB磁盘IO问题的三种方法
    javascript 利用匿名函数对象给你异步回调方法传参数
    spring mvc fastJson 自定义类型转换(返回数据) 实现对ObjectId类型转换
    Java BigDecimal 加减乘除运算
    OKHTTP 3.0
    Chrome 开发者工具中的命令菜单
    vuex 基础:教程和说明
    RxJS 简介:可观察对象、观察者与操作符
    CreateJs入门必知必会
  • 原文地址:https://www.cnblogs.com/gongpixin/p/6794503.html
Copyright © 2011-2022 走看看