For each of up to 100 test cases, decide whether two simple graphs on 3 vertices given by their edge lists are isomorphic.
Easy2GraphBrute forceImplementationNo attempts yetTime limit1sMemory limit256 MBLászló Babai is a Hungarian computer scientist and mathematician. He won the Gödel Prize, and he works on the theory of computation, algorithms, combinatorics, and group theory. He gave an algorithm that decides Graph Isomorphism in exp((logn)O(1)) time. The best time known before that was exp(O(nlogn)).
Graph Isomorphism asks the following. Two undirected graphs A=(VA,EA) and B=(VB,EB) are given, where VA={a1,a2,…,anA} and VB={b1,b2,…,bnB}. The graphs A and B are isomorphic if and only if both conditions hold.
In other words, relabeling the vertices of A produces B.
Nobody knows whether Graph Isomorphism is in P, and nobody knows whether it is NP-complete. Take the first step of that challenge and decide whether two undirected simple graphs on 3 vertices are isomorphic.
The first line has one integer T (1≤T≤100), the number of test cases.
Each test case gives two graphs in a row, both in the same format. The description of one graph starts with the number of edges m (0≤m≤3) of an undirected simple graph on 3 vertices numbered 1 to 3. Then m lines follow, each holding two distinct integers u and v (u=v, u,v∈{1,2,3}), which means that an edge joins vertex u and vertex v. At most one edge joins any pair of vertices.
For each test case, print yes on its own line if the two graphs are isomorphic, and no otherwise.