CF2193G.Paths in a Tree
提高+/省选-
通过率:0%
时间限制:4.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is an interactive problem.
In this interactive problem, you are given an acyclic, connected, undirected graph consisting of n vertices. We define a path between two vertices v and u as a sequence of distinct vertices p1,p2,…pk such that p1=v, pk=u, and for all i (1≤i<k), there exists an edge between vertices pi and pi+1.
There are hidden vertices x and y (they may coincide). You can make the following queries:
- Choose two vertices a, b (1≤a,b≤n). The jury will respond with 1 if the path between vertices x, y and the path between vertices a, b share at least one common vertex, and will respond with 0 otherwise.
Your task is to find at least one vertex on the path between x and y in no more than ⌊2n⌋+1 queries.
Note that the interactor is adaptive, which means that the hidden vertices may change depending on your queries, but will not contradict previous queries.
这是一个交互式问题。
在本交互式问题中,你将得到一个由 n 个顶点构成的无环、连通、无向图。我们定义两个顶点 v 和 u 之间的一条路径为一个由互不相同的顶点组成的序列 p1,p2,…pk,满足 p1=v,pk=u,且对所有 i(1≤i<k),顶点 pi 与 pi+1 之间存在一条边。
存在两个隐藏顶点 x 和 y(它们可能重合)。你可以进行如下查询:
- 选择两个顶点 a、b(1≤a,b≤n)。评测系统将返回 1,当且仅当顶点 x 与 y 之间的路径和顶点 a 与 b 之间的路径至少有一个公共顶点;否则返回 0。
你的任务是在至多 ⌊2n⌋+1 次查询内,找出 x 与 y 之间路径上的至少一个顶点。
注意:该交互器是自适应的,这意味着隐藏顶点可能根据你的查询而改变,但其变化不会与之前的所有查询结果产生矛盾。
输入格式
Each test consists of several test cases. The first line contains one integer t (1≤t≤104) — the number of test cases. The following lines describe the test cases.
The first line of each test case contains one integer n (2≤n≤2⋅105) — the number of vertices in the graph.
Next, there are n−1 lines, each containing two integers v, u (1≤v,u≤n), indicating that vertices v and u are connected by an edge in the graph.
It is guaranteed that the sum of n across all test cases does not exceed 2⋅105.
每个测试包含若干个测试用例。第一行包含一个整数 t(1≤t≤104),表示测试用例的数量。接下来的行描述各个测试用例。
每个测试用例的第一行包含一个整数 n(2≤n≤2⋅105),表示图中顶点的数量。
随后是 n−1 行,每行包含两个整数 v 和 u(1≤v,u≤n),表示顶点 v 和 u 在图中由一条边相连。
保证所有测试用例的 n 值之和不超过 2⋅105。
输入输出样例
输入#1
3 2 1 2 1 3 1 2 1 3 0 0 4 1 2 2 3 2 4 0 1
输出#1
? 1 1 ! 1 ? 1 1 ? 2 2 ! 3 ? 1 3 ? 4 4 ! 4
输入解题思路,AI测评打分。不知道怎么写?