Check if the Graph is a Butterfly

Given an undirected graph with only 5 vertices and e edges, you are asked to check if it’s a butterfly.
A butterfly graph is a graph that has five nodes, with one central node and four nodes connected to it. The central node has two nodes connected to it, and those two nodes are connected to each other, on one side. On the other side, it also has two nodes connected to the central one, and those two are connected to each other.
notion image


The first line of the input contains a single integer e (1 ≀ e ≀ 20).
The following e lines contain pairs of integers v1, v2 (1 ≀ v1, v2 ≀ 5) which means that the vertex v1 is connected to the vertex v2.


The program should print Yes if the graph is a butterfly, and No otherwise.


6 1 4 1 3 3 4 4 2 4 5 2 5


Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue