← All problemsSign in

Subway Ride

CodeChefRating 2774Open on judge ↗

Being a newcomer to Computopia, Chef is confused by the countless subway lines in the city. Help him! You are given an undirected graph with $N$ vertices and $M$ edges. There are no self-loops and no simple cycles that contain more than 2 edges in the graph (i.e. if we replaced each set of multiple edges connecting the same pair of vertices by one edge, we would obtain a tree). Each edge also has

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start