Cactus or not
InterviewTime limit1sMemory limit32 MB
Decide whether a connected undirected graph is a cactus where each vertex lies on at most one simple cycle.
Problem
A cactus is an undirected graph in which every vertex lies on at most one simple cycle. A simple cycle is a closed walk that returns to the vertex it started from without visiting any vertex twice.
If two cycles share a vertex, that vertex lies on two simple cycles, so the graph is not a cactus. Two triangles that meet at a single vertex already fail the condition.
You are given a connected graph. Decide whether it is a cactus.
Input
The first line contains two integers and , the number of vertices and the number of edges, separated by a space. ()
Each of the next lines contains two integers and , the endpoints of one edge, separated by a space. (, )
No edge is given twice, and a path exists between every pair of vertices.
Output
Print Cactus if the given graph is a cactus, and Not cactus otherwise.