主页
题目
状态
排名
OI排名
统计
题解
请登录
常用链接
AOJ考试平台
老赵的Gitee代码
编译原理模拟考试平台
Java技术手册
FCC网站
菜鸟网
在线工具箱
字节豆包GPT
代码可视化
力扣网
牛客网
洛谷
杭电OJ
CodeForce
隐藏编译器
Problem C: Friends
上一题
正确率: $62.50\%$
下一题
Time Limit
$1$ 秒/Second(s)
Memory Limit
$512$ 兆字节/Megabyte(s)
提交总数
$16$
正确数量
$10$
裁判形式
标准裁判/Standard Judge
我的状态
尚未尝试
难度
分类标签
树
回溯
搜索
×
为本题添加算法分类(请不要超过5个)
当前分类(单击移除):
树
回溯
搜索
单击选择分类:
Description
<p><span style="font-size: larger;"> 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? </span></p>
Input
<div title="Page 4"> <div> <div> <p><span style="font-size: larger;"> In the first line, there is an integer T, indicates the number of the cases.<br /> For each case, there is an integer N indicates the number of people in the first line.<br /> </span></p> <p><span style="font-size: larger;">In the next N-1 lines, there are two integers u and v, indicate the people u and the people </span></p> </div> </div> </div> <p><span style="font-size: larger;">v are acquainted with each other directly. People labels from 1. </span></p>
Output
<div title="Page 4"> <div> <div> <p><span style="font-size: larger;"> For each case, the first line is “Case #k :”, k indicates the case number. </span></p> </div> </div> </div> <p><span style="font-size: larger;"> 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. </span></p>
Sample Input
1 8 1 2 2 3 3 4 4 5 5 6 6 7 7 8
Sample Output
Case #1: 6 7 7 7 7 7 7 6
登录后提交代码
题面与样例可直接查看,登录后即可在线提交和评测。
前往登录