Explanation and Solution for CSES-1707: Graph Girth.
This solution uses BFS to both detect cycles and compute the length of the shortest one. Revisited cells indicate cycles, and we can use their computed distances to find the length of the shortest cycle.
Problem: https://cses.fi/problemset/task/1707
Code is in C++, Java, and Python
0:00 Intro
0:27 Sample Case
0:53 Observations
1:30 BFS (Idea)
2:26 BFS (Sample Walkthrough)
4:00 Implementation
4:46 CPP
6:03 Java
7:33 Python