Change Segment Colors

Problem Overview

  • Process m operations on an acyclic map of n stations: recolor edges on the path from a to b and answer black-edge counts on that path.
  • Input (array of strings): n m; n-1 edges u v; m lines op a b (a ≠ b). Output: for each op=2, count black segments on a to b.
  • All segments start red; for op=1, for each station on a to b set incident edges red, then set the path edges black.
  • Models color updates on a transport/network map.
  • From Trend_micro interviews; a coding interview problem and interview question.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: