Graph Theory37 sections · 1633 units
Open in Course

Flight Routes Check - Approach

(SCC count)

Run Kosaraju or Tarjan to find all SCCs. Count how many distinct SCCs exist. If there is exactly one SCC containing all nn nodes, print "YES" (the graph is strongly connected). If there are two or more SCCs, print "NO" followed by two cities aa and bb in different SCCs.

It does not matter which pair you choose as long as they are in different components. Either aa cannot reach bb or bb cannot reach aa (or both).