You are given a tree — associated undirected chart without cycles. One vertex of the tree is exceptional, and you need to track down which one. You can pose inquiries in the accompanying structure: given an edge of the tree, which endpoint is nearer to the uncommon vertex, which means which endpoint's most brief way to the extraordinary
Correct answer will be upvoted else Multiple Downvoted. Don't submit random answer. Computer science.
You are given a tree — associated undirected chart without cycles. One vertex of the tree is exceptional, and you need to track down which one. You can pose inquiries in the accompanying structure: given an edge of the tree, which endpoint is nearer to the uncommon vertex, which means which endpoint's most brief way to the extraordinary vertex contains less edges. You need to track down the uncommon vertex by posing the base number of inquiries in the most pessimistic scenario for a given tree.
If it's not too much trouble, note that the exceptional vertex probably won't be fixed by the interactor ahead of time: it may change the vertex to some other one, with the prerequisite of being steady with the recently offered responses.
Input
You are given an integer n (2≤n≤100) — the number of vertices in a tree.
The folloiwing n−1 lines contain two integers every, u and v (1≤u,v≤n), that signify an edge in the tree interfacing u and v. It is ensured that the given edges structure a tree.
Connection
Subsequent to perusing the input information, one can begin making inquiries. There are two potential questions:
"? u v" — to request an edge (u,v) (1≤u,v≤n) which of the endpoints is nearer to the uncommon vertex. The response to this inquiry is one of the endpoints. Note that, u and v should be associated by an edge, and consequently they can not have a similar distance to the uncommon vertex.
"! u" — to demonstrate that you tracked down the unique vertex. After the
Remember to output the finish of line and flush the output. If not you will get Idleness limit surpassed decision. To flush the output, you can utilize:
fflush(stdout) or cout.flush() in C++;
System.out.flush() in Java;
flush(output) in Pascal;
sys.stdout.flush() in Python;
see documentation for different dialects.
In the event that you ask a bigger number of inquiries than required in the most pessimistic scenario for a given tree, you will find decision Wrong solution.
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)