| Task: | Building Teams |
| Sender: | aalto26bm_043 |
| Submission time: | 2026-09-07 17:08:42 +0300 |
| Language: | C++ (C++23) |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | WRONG ANSWER | 0.00 s | details |
| #2 | WRONG ANSWER | 0.00 s | details |
| #3 | WRONG ANSWER | 0.00 s | details |
| #4 | WRONG ANSWER | 0.00 s | details |
| #5 | WRONG ANSWER | 0.00 s | details |
| #6 | WRONG ANSWER | 0.29 s | details |
| #7 | WRONG ANSWER | 0.29 s | details |
| #8 | WRONG ANSWER | 0.28 s | details |
| #9 | WRONG ANSWER | 0.28 s | details |
| #10 | WRONG ANSWER | 0.29 s | details |
| #11 | WRONG ANSWER | 0.00 s | details |
| #12 | WRONG ANSWER | 0.00 s | details |
Code
#include <iostream>
#include <unordered_set>
#include <unordered_map>
void add_friends(int pupil, const std::unordered_map<int, std::unordered_set<int>> &friendships, std::unordered_set<int>& group_friends){
if(group_friends.contains(pupil)){
return;
}
//first, add the current pupil
group_friends.insert(pupil);
//then, add this pupils friends
if(friendships.contains(pupil)){
for (const auto & pupil_friend : friendships.at(pupil)){
// group_friends.insert(pupil);
add_friends(pupil_friend, friendships, group_friends);
}
}
}
int main(){
int num_pupils, num_frendships;
std::unordered_map<int, std::unordered_set<int>> friendships{};
std::cin >> num_pupils;
std::cin >> num_frendships;
for(int i=0; i<num_frendships; i++){
int friend1, friend2;
std::cin >> friend1 >> friend2;
friendships[friend1].insert(friend2);
}
std::unordered_set<int> group1, group2;
std::unordered_set<int> group1_friends, group2_friends;
// now, we'll add the first pupil into the first group
// and then iterate over the rest and add them to the 1st one if they have no friends there
// and if no, then we add them to the second one, if they also have no friends there
// ughhhh but I know this is so no optimal fuck
for(int pupil = 1; pupil<= num_pupils; pupil++){
if(!group1_friends.contains(pupil)){
group1.insert(pupil);
add_friends(pupil, friendships, group1_friends);
}
else if(not group2_friends.contains(pupil)){
group2.insert(pupil);
add_friends(pupil, friendships, group2_friends);
} else {
std::cout << "IMPOSSIBLE";
break;
}
}
for(int i=1; i<=num_pupils; i++){
std::cout << (group1.contains(i) ? "1" : "2" ) << " ";
}
std::cout << "\n";
}Test details
Test 1
Verdict: WRONG ANSWER
| input |
|---|
| 10 20 3 4 8 10 3 7 1 8 ... |
| correct output |
|---|
| 1 1 1 2 2 1 2 2 2 1 |
| user output |
|---|
| IMPOSSIBLE1 1 1 2 2 2 2 2 2 2 |
Test 2
Verdict: WRONG ANSWER
| input |
|---|
| 10 20 1 3 8 10 2 4 6 8 ... |
| correct output |
|---|
| 1 1 2 2 1 1 1 2 1 1 |
| user output |
|---|
| IMPOSSIBLE1 1 2 2 2 2 2 2 2 2 |
Test 3
Verdict: WRONG ANSWER
| input |
|---|
| 10 20 7 10 3 10 9 10 2 10 ... |
| correct output |
|---|
| 1 2 2 1 1 1 2 1 2 1 |
| user output |
|---|
| IMPOSSIBLE1 1 1 2 2 2 2 2 2 2 |
Test 4
Verdict: WRONG ANSWER
| input |
|---|
| 10 20 2 4 2 10 7 10 4 6 ... |
| correct output |
|---|
| 1 2 1 1 2 2 2 1 2 1 |
| user output |
|---|
| IMPOSSIBLE1 2 2 2 2 2 2 2 2 2 |
Test 5
Verdict: WRONG ANSWER
| input |
|---|
| 10 20 3 5 8 10 9 10 1 8 ... |
| correct output |
|---|
| IMPOSSIBLE |
| user output |
|---|
| IMPOSSIBLE1 1 1 2 2 2 2 2 2 2 |
Test 6
Verdict: WRONG ANSWER
| input |
|---|
| 100000 200000 47355 96505 90709 92058 735 80715 91802 94265 ... |
| correct output |
|---|
| 1 2 2 1 2 1 1 1 2 2 1 2 1 1 1 ... |
| user output |
|---|
| IMPOSSIBLE1 1 1 1 1 1 1 1 1 1 ... |
Test 7
Verdict: WRONG ANSWER
| input |
|---|
| 100000 200000 59991 95794 95150 96051 78453 94730 90411 95523 ... |
| correct output |
|---|
| 1 1 1 2 2 1 1 2 1 2 1 2 2 2 1 ... |
| user output |
|---|
| IMPOSSIBLE1 1 1 1 1 1 1 1 1 1 ... |
Test 8
Verdict: WRONG ANSWER
| input |
|---|
| 100000 200000 89827 96402 65137 86792 80965 94708 19479 48078 ... |
| correct output |
|---|
| 1 2 1 1 2 1 2 2 2 1 2 1 1 2 1 ... |
| user output |
|---|
| IMPOSSIBLE1 1 1 1 1 1 1 1 1 1 ... |
Test 9
Verdict: WRONG ANSWER
| input |
|---|
| 100000 200000 72952 83723 66197 70052 2949 52160 55753 95651 ... |
| correct output |
|---|
| 1 1 2 2 2 1 1 2 2 2 2 2 1 2 1 ... |
| user output |
|---|
| IMPOSSIBLE1 1 1 1 1 1 1 1 1 1 ... |
Test 10
Verdict: WRONG ANSWER
| input |
|---|
| 100000 200000 38942 96755 70049 82663 7746 72732 87819 99029 ... |
| correct output |
|---|
| IMPOSSIBLE |
| user output |
|---|
| IMPOSSIBLE1 1 1 1 1 1 1 1 1 1 ... |
Test 11
Verdict: WRONG ANSWER
| input |
|---|
| 5 4 1 2 3 4 4 5 5 3 |
| correct output |
|---|
| IMPOSSIBLE |
| user output |
|---|
| IMPOSSIBLE1 2 1 2 2 |
Test 12
Verdict: WRONG ANSWER
| input |
|---|
| 4 5 1 2 1 4 2 3 2 4 ... |
| correct output |
|---|
| IMPOSSIBLE |
| user output |
|---|
| IMPOSSIBLE1 2 2 2 |
