Lucky Cities
Time limit1sMemory limit128 MB
Given an undirected graph, count vertices that lie on at least one simple cycle of odd length.
- Level
Medium7 of 10
- Topics
- Graph, DFS, Union-find
- Solved
- No attempts yet
Problem
John has recently arrived in Romania for the South Eastern European Regional competition. Since John has never been to Romania before, the hosts decided to organize a sightseeing tour for him. Such a tour includes several Romanian cities, and none of them is visited more than once. John starts in one city, visits some other cities according to a guided route, and at the end of the tour returns to the starting point.
There are cities numbered from 1 to and two-way roads in the country. Each road connects two different cities. A sightseeing tour for John is a sequence of cities such that all are distinct, and are connected by a road for , and and are connected by a road as well.
Being an odd person, John would like to visit an odd number of cities. The organizers have drawn the plans of all possible tours with an odd number of cities, and only such tours are considered.
The residents of a city would love John to visit them. A city is called lucky if there is at least one such tour (with an odd number of cities) passing through it. Your task is to compute the number of lucky cities in Romania.
Input
The first line of input contains a single integer — the number of test cases. Every test case starts with a line containing two integers separated by a single space — and . Each of the next lines contains two integers and separated by a single space — the labels of the cities that the -th road connects.
Output
The output should contain lines — the answer for each of the test cases, in order.