AltF4 and Spinal Network
Practice
3.8 (5 votes)
Approved
Medium
Open
Problem
69% Success 751 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

AltF4 is into his networking class and his teacher introduces him to bus topology. Being bored of the class, he his lost into his own thoughts where he discovers a new topology of his own - the Spinal Network. In this topology, we have a central line just like the bus topology. All the nodes (or hops, or computers) are either in the central line itself, or it is directly connected to the central line. To make things easier he says that the topology given should be a tree. Resembles the spinal cord, isn't it? Given a tree, you need to figure out if it is spinal or not.

Input & Output

The first line of the input contains the number of test cases T. Description of T test cases follow. Each test case starts with an integer N the number of nodes in the tree. N - 1 lines follow each containing two integers U V, the nodes which have an edge between them.

NOTE : Large Input Files. Use faster IO.

For each test case, output "YES" if the tree given is Spinal else output "NO". Quotes are for clarity only and should not be printed.

Constraints
T ≤ 500
N ≤ 10000
1 ≤ U, V ≤ N

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
6 votes
Tags:
AlgorithmsDepth First SearchGraphsMedium
Points:30
4 votes
Tags:
Depth First SearchAlgorithmsGraphs
Points:30
33 votes
Tags:
AlgorithmsDepth First SearchGraphs