CF1444E.Finding the Vertex
NOI/NOI+/CTSC
通过率:0%
时间限制:1.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is an interactive problem.
You are given a tree — connected undirected graph without cycles. One vertex of the tree is special, and you have to find which one. You can ask questions in the following form: given an edge of the tree, which endpoint is closer to the special vertex, meaning which endpoint's shortest path to the special vertex contains fewer edges. You have to find the special vertex by asking the minimum number of questions in the worst case for a given tree.
Please note that the special vertex might not be fixed by the interactor in advance: it might change the vertex to any other one, with the requirement of being consistent with the previously given answers.
这是一个交互式问题。
你将得到一棵树——即一个无环的连通无向图。树中有一个特殊顶点,你需要找出它是哪一个。你可以提出如下形式的问题:给定树中的一条边,询问该边的两个端点中哪一个离特殊顶点更近(即哪一个端点到特殊顶点的最短路径所含的边数更少)。你需要在最坏情况下,通过尽可能少的提问次数,确定该特殊顶点(针对给定的树)。
请注意,特殊顶点可能并非由交互器预先固定:它可以在任意时刻将特殊顶点更换为树中任意其他顶点,但必须保证所有此前给出的回答依然成立(即保持一致性)。
输入格式
You are given an integer n (2≤n≤100) — the number of vertices in a tree.
The folloiwing n−1 lines contain two integers each, u and v (1≤u,v≤n), that denote an edge in the tree connecting u and v. It is guaranteed that the given edges form a tree.
给你一个整数 n(2≤n≤100)—— 表示一棵树的顶点数。
接下来的 n−1 行每行包含两个整数 u 和 v(1≤u,v≤n),表示树中连接顶点 u 和 v 的一条边。保证所给的边构成一棵树。
输入输出样例
输入#1
5 1 2 2 3 3 4 4 5 3 2 1
输出#1
? 3 4 ? 2 3 ? 1 2 ! 1
输入#2
5 2 1 3 1 4 1 5 1 1 1 4
输出#2
? 1 2 ? 1 3 ? 1 4 ! 4
说明/提示
Hacks are forbidden in this task.
本题禁止使用作弊手段。
输入解题思路,AI测评打分。不知道怎么写?