Graph Theory37 sections · 1633 units
Open in Course

CSES 1668 Building Teams - Walkthrough

Trace example

let's trace n=4n = 4, m=3m = 3, edges: (1,2)(1,2), (2,3)(2,3), (3,4)(3,4). This is a path: 11-22-33-44. BFS from 11: color[1] = 0. Neighbor 22: color[2] = 1. Neighbor of 22: 11 (already 00, good), 33 (color[3] = 0).

Neighbor of 33: 22 (already 11, good), 44 (color[4] = 1). Final: color = [-1, 0, 1, 0, 1]. Output: "11 22 11 22" (adding 11 to each). Team 11: pupils 11, 33. Team 22: pupils 22, 44.