Solution: Paths in Maze That Lead to Same Room
Explore how to identify and count cycles of length three in a maze represented as a graph. This lesson guides you through using adjacency lists and set intersections to detect interconnected rooms forming triangular cycles efficiently, helping you analyze graph confusion scores with optimized time and space complexity.
Statement
A maze consists of rooms numbered from , and some rooms are connected by corridors. You are given a 2D integer array, corridors, where indicates that there is a corridor connecting and , allowing a person in the maze to go from to and vice versa.
The designer of the maze wants to know how confusing the maze is. The confusion score of the maze is the number of different cycles of length 3.
For example, is a cycle of length , but ...