Solution for Building Teams #121
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🎯 Problem Information
Problem Name: Building Teams
Category: Graph (Bipartite Check, DFS/BFS)
CSES Link: https://cses.fi/problemset/task/1668
Difficulty: [Medium]
#120
📝 Description
This PR adds a clean, well-documented C++ solution for the Building Teams problem from CSES.
The program determines if it is possible to divide all students into two teams such that no two friends are in the same team.
If possible, it prints one valid team assignment for each student (either
1or2).If not possible, it prints
IMPOSSIBLE.🧩 Solution Approach
1to a node, and alternate colors for its neighbors.IMPOSSIBLE.✅ Checklist
Please ensure your PR meets these requirements:
Code Quality
adj,color,queue,ok)Testing
N ≤ 1e5,M ≤ 2e5)Documentation
graphs/)building_teams.cpp)Style Guide
#include <bits/stdc++.h>)ios::sync_with_stdio(false); cin.tie(nullptr);)intacceptable here)🏷️ Type of Change
🧪 Testing Details
Test Cases Used:
Input:
5 3
1 2
1 3
4 5
Expected Output:
1 2 2 1 2
Actual Output:
1 2 2 1 2
Input:
3 3
1 2
2 3
3 1
Expected Output:
IMPOSSIBLE
Actual Output:
IMPOSSIBLE
Input:
1 0
Expected Output:
1
Actual Output:
1
📸 Screenshots (if applicable)
📎 Additional Notes
IMPOSSIBLEif any component is not bipartite.For Maintainers:
graphs,good first issue, `hacktoberfest