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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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 program does that, it should quickly end. 

 

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.

 

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Types of trees
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education