Grand Test
Time limit3sMemory limit512 MB
For each undirected graph, decide whether some pair of vertices admits three routes whose internal vertices and edges are all disjoint.
- Level
Medium7 of 10
- Topics
- Graph, DFS, Binary search, Implementation
- Solved
- No attempts yet
Problem
Jeremy, Richard and James like to test cars. Deciding where to run a test is always hard. They pick a country and look at its cities and the two-way roads between them.
A test needs two different cities and and three routes from to . A route is a sequence of cities with , , and a road between and for every with . No city appears twice inside one route.
The three routes must meet two conditions. Every city other than and appears in at most one of the three routes. No road is used by more than one route.
When such , and three routes exist, each of the three takes a car in , drives along one of the routes and tries to reach before the others.
You are given the description of several countries. For each country, decide whether two cities and three routes can be chosen this way.
Input
The first line contains the number of countries (). The descriptions of countries follow.
The first line of each country contains the number of cities and the number of roads (). The next lines contain the cities and at the ends of a road (). All roads are two-way, and at most one road joins any pair of cities.
The sum of over all countries and the sum of over all countries are each at most .
Output
For each country print one line. Print YES if two cities and and three routes meeting the conditions exist, and NO otherwise. Print the answers in the order the countries are given in the input.