Graph Theory37 sections · 1633 units
Open in Course

LeetCode 1334 Find the City - Walkthrough

(LeetCode example trace)

Sample: n=4n=4, edges =[(0,1,3),(1,2,1),(1,3,4),(2,3,1)]= [(0,1,3), (1,2,1), (1,3,4), (2,3,1)], threshold =4= 4. After Floyd-Warshall: dist[0][1]=3, dist[0][2]=4, dist[0][3]=5, etc. City 00 reaches cities 11 and 22 (count =2= 2). City 33 reaches cities 11 and 22 (count =2= 2).

Tied at 22. Return city 33 (larger index). This example shows how ties are resolved by returning the higher-numbered city. The tie-breaking rule is part of the problem statement.