Graph Theory37 sections · 1633 units
Open in Course

LeetCode 1334 Find the City - Lessons

Post-processing distance ma...

This problem shows how Floyd-Warshall enables post-processing on the distance matrix. Once you have dist[i][j] for all pairs, you can answer complex queries: count neighbors within threshold, find min/max paths, etc.

The O(n3)O(n^3) precomputation pays off when you need flexible queries on distances. The pattern is: build the matrix once, use it many times. This is common in graph problems with multiple queries.