Thanks to visit codestin.com
Credit goes to github.com

Skip to content

You have a graph with N vertices and M edges. Someone has chosen N-1 edges of these M and claims that they form a spanning tree. Just check whether it's true or not. Input The first line contains one integer T denoting the number of test cases. Each test case starts with a line containing 2 space-separated integers: N and M. Each of the followin…

Notifications You must be signed in to change notification settings

Mnnu-Ann/Check-It---HackerEarth-Java-Solution

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Check-It---HackerEarth-Java-Solution

You have a graph with N vertices and M edges.

Someone has chosen N-1 edges of these M and claims that they form a spanning tree.

Just check whether it's true or not.


Input

The first line contains one integer T denoting the number of test cases.

Each test case starts with a line containing 2 space-separated integers: N and M.

Each of the following M lines contains description of one edge: two different space-separated integers a and b from 1 to N

each - numbers of vertices that are connected by this edge.

The last line of each test case contains N - 1 space-separated integers - numbers of chosen edges.

Edges are enumerated from 1 in the input order.


Output

For each test case output either YES if the chosen N-1 edges form a spanning tree or NO otherwise.


Constraints

1 <= T <= 20

1 <= N <= 5000

1 <= M <= 40 000

About

You have a graph with N vertices and M edges. Someone has chosen N-1 edges of these M and claims that they form a spanning tree. Just check whether it's true or not. Input The first line contains one integer T denoting the number of test cases. Each test case starts with a line containing 2 space-separated integers: N and M. Each of the followin…

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages