Sanggeun's travels
Time limit1sMemory limit256 MB
Given a connected graph of N countries and M flights, find the fewest flights that visit every country.
- Level
Easy2 of 10
- Topics
- Graph
- Solved
- No attempts yet
Problem
Sanggeun decided to spend the winter break traveling through countries and finding himself. He is scared of planes he has never been on, so he wants to ride as few kinds of planes as possible while moving between countries.
Given the flight schedule for this break, find the smallest number of plane kinds Sanggeun needs in order to visit every country.
On the way from one country to another he may pass through other countries, including ones he has already visited.
Input
The first line contains the number of test cases . ()
Each test case is given as follows.
- The first line contains the number of countries and the number of plane kinds . (, )
- Each of the next lines contains two integers and , meaning there is a plane that flies back and forth between and . (, )
The given flight schedule always forms a connected graph.
Output
For each test case, print on one line the minimum number of plane kinds Sanggeun has to ride to travel to every country.