Isomorphic?
Time limit2sMemory limit1024 MB
Given two connected graphs, each with N vertices and N edges, decide whether they are isomorphic.
- Level
Medium6 of 10
- Topics
- Graph, Tree, String matching, Hash map
- Solved
- No attempts yet
Problem
You are given two undirected simple connected graphs and . Each graph has vertices numbered from to and edges.
Determine whether the two graphs are isomorphic. That is, decide whether a permutation of exists such that for every pair of vertices and , has an edge between and if and only if has an edge between and .
Input
The first line contains one integer ().
Each of the next lines contains two integers and (), meaning that has an undirected edge between vertices and .
Each of the following lines contains two integers and (), meaning that has an undirected edge between vertices and .
Both graphs are connected, and neither has self-loops or double edges.
N
a_1 b_1
...
a_N b_N
c_1 d_1
...
c_N d_N
Output
Print Yes if and are isomorphic, and No otherwise.