Problem Statement | |||||||||||||
A vertex cactus is a connected undirected graph such that each vertex belongs to at most one simple cycle. A simple cycle is a cycle that doesn't pass through any vertex more than once. For example, the graph pictured below is a vertex cactus:
You are given an int n, the number of vertices in a graph G. The vertices are numbered from 1 to n. The edges in G are given in the String[] edges. Concatenate the elements of edges to get a comma-separated list of integer pairs. The integers in each pair are separated by a space. The pair "i j" (quotes for clarity) means that there is an edge between vertices i and j. Return the number of connected components of G that are vertex cacti. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
- | A connected component of a graph G is a set of vertices such that each pair of vertices in the set is connected by a path, and no vertex outside the set is connected to any vertex within the set. | ||||||||||||
Constraints | |||||||||||||
- | n will be between 1 and 200, inclusive. | ||||||||||||
- | edges will contain between 0 and 50 elements, inclusive. | ||||||||||||
- | Each element of edges will contain between 1 and 50 characters, inclusive. | ||||||||||||
- | When concatenated, edges will contain a comma separated list of integer pairs. | ||||||||||||
- | The integers within each pair will be separated by a space. | ||||||||||||
- | The integers within each pair will be distinct. | ||||||||||||
- | Each integer will be between 1 and n, inclusive, with no leading zeroes. | ||||||||||||
- | Every pair of vertices will be connected by at most one edge. | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
| |||||||||||||
3) | |||||||||||||
|