László Babai
Time limit1sMemory limit256 MB
For each of up to 100 test cases, decide whether two simple graphs on 3 vertices given by their edge lists are isomorphic.
- Level
Easy2 of 10
- Topics
- Graph, Brute force, Implementation
- Solved
- No attempts yet
Problem
Lá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 time. The best time known before that was .
Graph Isomorphism asks the following. Two undirected graphs and are given, where and . The graphs and are isomorphic if and only if both conditions hold.
- and have the same number of vertices and the same number of edges.
- There is a bijection such that if and only if .
In other words, relabeling the vertices of produces .
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.
Input
The first line has one integer (), 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 () of an undirected simple graph on 3 vertices numbered 1 to 3. Then lines follow, each holding two distinct integers and (, ), which means that an edge joins vertex and vertex . At most one edge joins any pair of vertices.
Output
For each test case, print yes on its own line if the two graphs are isomorphic, and no otherwise.