Problem 1860 --Friends

1860: Friends

"
Time Limit $1$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $16$ 正确数量 $10$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签 回溯 搜索

    In a country, the relationship between people can be indicated by a tree. If two people are acquainted with each other, there will be an edge between them. If a person can get in touch with another through no more than five people, we should consider these two people can become friends. Now, give you a tree of N people’s relationship. ( 1 <= N <= 1e5), you should compute the number of who can become friends of each people?  

    In the first line, there is an integer T, indicates the number of the cases.
    For each case, there is an integer N indicates the number of people in the first line.
   

In the next N-1 lines, there are two integers u and v, indicate the people u and the people

v are acquainted with each other directly. People labels from 1.  

    For each case, the first line is “Case #k :”, k indicates the case number.

    In the next N lines, there is an integer in each line, indicates the number of people who can become the ith person’s friends. i is from 1 to n.  

1 
8 
1 2 
2 3 
3 4 
4 5 
5 6 
6 7 
7 8

Case #1:
6
7
7
7
7
7
7
6

推荐代码 查看1860 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$159 $ms] 淡意的温柔 588181 2020-05-28 11:02:50
内存最少[$9380 $KB] 胡春宇@计算机科学与技术162 99268 2017-06-01 09:33:39
第一AC 张曼曼@烹饪与营养教育151 98008 2017-05-31 09:02:34
第一挑战 AOJ大管家 84149 2017-04-26 12:51:58

赛题来源/所属竞赛 NA N/A

竞赛编号 竞赛名称 竞赛时间 访问比赛
1084 2016-2017-2学期《C语言程序设计II》课程课下作业~ 2017-05-19 00:00:00 请登录