主页
试题仓库
题目列表
试题分类
经典教材
作业竞赛
作业列表
判题队列
图灵学院
TuringMOOC
图灵书屋
图灵商城
图灵实验室
图灵会员
荣誉成绩
捐赠支持
图灵云编译器
用户/排名
AOJ排名
实名认证
请登录
常用链接
AOJ考试平台
老赵的Gitee代码
编译原理模拟考试平台
Java技术手册
FCC网站
菜鸟网
在线工具箱
字节豆包GPT
代码可视化
力扣网
牛客网
洛谷
杭电OJ
CodeForce
隐藏编译器
Problem 3057 --Rikka with Travels
3057: Rikka with Travels
上一题
正确率: $0.00\%$
下一题
Time Limit
$2$ 秒/Second(s)
Memory Limit
$512$ 兆字节/Megabyte(s)
提交总数
$1$
正确数量
$0$
"
裁判形式
标准裁判/Standard Judge
我的状态
尚未尝试
难度
分类标签
×
为本题添加算法分类(请不要超过5个)
当前分类(单击移除):
单击选择分类:
Description
<span style="font-family:"font-size:14px;">To enjoy their summer vacations, Rikka and Yuta decide to go travels. According to past experiences, contradictions always arose when they were planning for the same trip. This time, they decide to make plans dividually and will go travel twice.</span><br /> <br /> <span style="font-family:"font-size:14px;">Coincidentally, they choose the same country Fantasy as the destination, which is a small island country on the Pacific. There are </span><span class="MathJax_Preview" style="color:#888888;font-family:"font-size:14px;"></span>n<span style="font-family:"font-size:14px;"> cities in Fantasy and they are connected with </span><span class="MathJax_Preview" style="color:#888888;font-family:"font-size:14px;"></span>n−1<span style="font-family:"font-size:14px;"> two-way roads. It is guaranteed that any two cities can reach each other by the road system.</span><br /> <br /> <span style="font-family:"font-size:14px;">Though Rikka and Yuta love travels, visiting the same city more than once is still boring for them. Therefore, both Rikka and Yuta choose a simple path (i.e., a path without visiting any city more than once) as her/his plan. Moreover, they want to ensure the two paths do not intersect on any city.</span><br /> <br /> <span style="font-family:"font-size:14px;">Suppose Rikka chooses the path from </span><span class="MathJax_Preview" style="color:#888888;font-family:"font-size:14px;"></span>a<span style="font-family:"font-size:14px;"> to </span><span class="MathJax_Preview" style="color:#888888;font-family:"font-size:14px;"></span>b<span style="font-family:"font-size:14px;">, Yuta chooses the path from </span><span class="MathJax_Preview" style="color:#888888;font-family:"font-size:14px;"></span>c<span style="font-family:"font-size:14px;"> to </span><span class="MathJax_Preview" style="color:#888888;font-family:"font-size:14px;"></span>d<span style="font-family:"font-size:14px;"> (both </span><span class="MathJax_Preview" style="color:#888888;font-family:"font-size:14px;"></span>a=b<span style="font-family:"font-size:14px;"> and </span><span class="MathJax_Preview" style="color:#888888;font-family:"font-size:14px;"></span>c=d<span style="font-family:"font-size:14px;"> are allowed), they define the feature of the plan is an ordered pair </span><span class="MathJax_Preview" style="color:#888888;font-family:"font-size:14px;"></span>(L(a,b),L(c,d))<span style="font-family:"font-size:14px;">, where </span><span class="MathJax_Preview" style="color:#888888;font-family:"font-size:14px;"></span>L(x,y)<span style="font-family:"font-size:14px;"> represents the number of cities on the path from </span><span class="MathJax_Preview" style="color:#888888;font-family:"font-size:14px;"></span>x<span style="font-family:"font-size:14px;"> to </span><span class="MathJax_Preview" style="color:#888888;font-family:"font-size:14px;"></span>y<span style="font-family:"font-size:14px;">.</span><br /> <br /> <span style="font-family:"font-size:14px;">Now, Rikka wants to count the number of different features, i.e., the number of different integer pairs </span><span class="MathJax_Preview" style="color:#888888;font-family:"font-size:14px;"></span>(l1,l2)<span style="font-family:"font-size:14px;"> which satisfies there exists a valid travel plan </span><span class="MathJax_Preview" style="color:#888888;font-family:"font-size:14px;"></span>(a,b,c,d)<span style="font-family:"font-size:14px;">meets </span><span class="MathJax_Preview" style="color:#888888;font-family:"font-size:14px;"></span>L(a,b)=l1,L(c,d)=l2<span style="font-family:"font-size:14px;">. Since Rikka and Yuta are busy with planning their trip, Rikka asks you to help her calculate the answer.</span>
Input
<span style="font-family:"font-size:14px;">The first line of the input contains a single integer </span><span class="MathJax_Preview" style="color:#888888;font-family:"font-size:14px;"></span>T(1≤T≤300)<span style="font-family:"font-size:14px;">, the number of test cases.</span><br /> <br /> <span style="font-family:"font-size:14px;">For each test case, the first line contains a single integer </span><span class="MathJax_Preview" style="color:#888888;font-family:"font-size:14px;"></span>n(1≤n≤105)<span style="font-family:"font-size:14px;">, the number of cities in Fantasy.</span><br /> <br /> <span style="font-family:"font-size:14px;">Then </span><span class="MathJax_Preview" style="color:#888888;font-family:"font-size:14px;"></span>n−1<span style="font-family:"font-size:14px;"> lines follow. Each line contains two integers </span><span class="MathJax_Preview" style="color:#888888;font-family:"font-size:14px;"></span>ui,vi(1≤ui,vi≤n)<span style="font-family:"font-size:14px;"> which represents a two-way road </span><span class="MathJax_Preview" style="color:#888888;font-family:"font-size:14px;"></span>(ui,vi)<span style="font-family:"font-size:14px;"> in the road system.</span><br /> <br /> <span style="font-family:"font-size:14px;">The input guarantees that there are no more than </span><span class="MathJax_Preview" style="color:#888888;font-family:"font-size:14px;"></span>5<span style="font-family:"font-size:14px;"> test cases with </span><span class="MathJax_Preview" style="color:#888888;font-family:"font-size:14px;"></span>n>500<span style="font-family:"font-size:14px;">.</span>
Output
<span style="font-family:"font-size:14px;">For each test case, output a single line with a single integer, the answer.</span>
Sample Input
2 4 1 2 1 3 1 4 5 1 2 2 3 3 4 3 5
Sample Output
5 10
提示
<span style="font-family:"font-size:14px;background-color:#F4FBFF;">In the first test case, the possible features are </span><span class="MathJax_Preview" style="color:#888888;font-family:"font-size:14px;"></span>(1,1),(1,2),(1,3),(2,1),(3,1)<span style="font-family:"font-size:14px;background-color:#F4FBFF;">. Therefore the answer is </span><span class="MathJax_Preview" style="color:#888888;font-family:"font-size:14px;"></span>5<span style="font-family:"font-size:14px;background-color:#F4FBFF;">.</span><br /> <br /> <span style="font-family:"font-size:14px;background-color:#F4FBFF;">In the second test case, the possible features are </span><span class="MathJax_Preview" style="color:#888888;font-family:"font-size:14px;"></span>(1,1),(1,2),(1,3),(1,4),(2,1),(2,2),(2,3),(3,1),(3,2),(4,1)<span style="font-family:"font-size:14px;background-color:#F4FBFF;">. Therefore the answer is </span><span class="MathJax_Preview" style="color:#888888;font-family:"font-size:14px;"></span>10<span style="font-family:"font-size:14px;background-color:#F4FBFF;">.</span>
推荐代码
查看3057 所有题解
上传题解视频得图灵币
本题记录
用 户(点击查看用户)
运行号(点击购买题解)
时 间
算法最快[$0 $ms]
0
内存最少[$0 $KB]
0
第一AC
0
第一挑战
淡意的温柔
588057
2020-05-27 09:44:46
赛题来源
2019 Multi-University Training Contest 9
登录后提交代码
题面与样例可直接查看,登录后即可在线提交和评测。
前往登录