Nyoj 20 Stingy Kingdom

Source: Internet
Author: User

Stingy Country time limit:MS | Memory limit:65535 KB Difficulty:3
Describe
there are n cities in a stingy country, and only N-1 roads connect the n cities between the N cities. Now, Tom in City number one, he has a map of the country, he wants to know if you want to visit the city of T, must go past the city is the number of cities (assuming you do not go the way of repetition).
Input
The first line enters an integer m for the test data Total m (1<=m<=5) group the first row of each set of test data enter a positive integer n (1<=n<=100000) and a positive integer S (1<=s<=100000), N indicates the total number of cities , s indicates the number of the city where the visitor is located followed by the N-1 line, with two positive integers a, B (1<=a,b<=n) per line, indicating a link between City A and City B.
Output
Each set of test data outputs n positive integers, where the number of I represents the number of the previous city that must pass from S to City I. (When i=s, please output-1)
Sample input
110 11 91 88 1010 38 61 210 49 53 7
Sample output
-1 1 10 10 9 8 3 1 1 8

Nyoj 20 Stingy Kingdom

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.