For each undirected graph, decide whether some pair of vertices admits three routes whose internal vertices and edges are all disjoint.
Medium7GraphDFSBinary searchImplementationNo attempts yetTime limit3sMemory limit512 MBJeremy, 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 S and F and three routes from S to F. A route is a sequence of cities v1,v2,…,vk with v1=S, vk=F, and a road between vi and vi+1 for every i with 1≤i≤k−1. No city appears twice inside one route.
The three routes must meet two conditions. Every city other than S and F appears in at most one of the three routes. No road is used by more than one route.
When such S, F and three routes exist, each of the three takes a car in S, drives along one of the routes and tries to reach F 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.
The first line contains the number of countries T (1≤T≤100000). The descriptions of T countries follow.
The first line of each country contains the number of cities n and the number of roads m (1≤n,m≤100000). The next m lines contain the cities ui and vi at the ends of a road (1≤ui<vi≤n). All roads are two-way, and at most one road joins any pair of cities.
The sum of n over all countries and the sum of m over all countries are each at most 100000.
For each country print one line. Print YES if two cities S and F and three routes meeting the conditions exist, and NO otherwise. Print the answers in the order the countries are given in the input.