##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
You know BFS and can traverse graphs. Some graphs split into two groups with no same-group edges.
The Goal
Core definition
The visual test
Two disjoint sets
Where they appear
Why some graphs fail
See the contradiction
Knowledge check
The plan
Level-by-level coloring
Recursive approach
Multiple components
Alternative approach
When to use each
What goes wrong
Analysis
LeetCode 785
Adjacency list
Tracking state
Same color neighbors
Handling all components
Step by step
The code
Trace example
When it fails
summary
Knowledge check
LeetCode 886
The party problem
It's bipartite!
Edge list to adj list
One-indexed vs zero-indexed
Same core logic
The code
Trace example
summary
Knowledge check
CSES
Competitive style
Print the teams
Same algo, new output
Step by step
The code
Trace example
summary
Knowledge check
Matching preview
What we learned