Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Every unvisited city starts a new DFS and one province. DFS marks all cities in that connected component.
A province is exactly one connected component in the undirected city graph, and each node is visited once from its component root.
Updated Feb 2026