Shortest Cycle in a Graph
Try to solve the Shortest Cycle in a Graph problem.
We'll cover the following...
We'll cover the following...
Statement
You are given a bidirectional graph with n
vertices, labeled from 0
to n - 1
. The graph is represented by a 2D integer array edges
, where each element edges[i] = [u
i
, v
i
]
represents an edge connecting vertex u
i
and vertex v
i
. Each vertex pair has at most one edge between them, and no vertex is connected to itself.
Your task is to find the length of the shortest cycle in the graph. A cycle is defined as a path that starts and ends at the same vertex, with each edge in the path appearing exactly once. If no cycle exists in the graph, return -1
.
Constraints:
...