Submission details
Task:Building Teams
Sender:aalto26bm_043
Submission time:2026-09-07 17:07:30 +0300
Language:C++ (C++20)
Status:COMPILE ERROR

Compiler report

input/code.cpp:5:40: error: 'unordered_map' in namespace 'std' does not name a template type
    5 | void add_friends(int pupil, const std::unordered_map<int, std::unordered_set<int>> &friendships, std::unordered_set<int>& group_friends){
      |                                        ^~~~~~~~~~~~~
input/code.cpp:3:1: note: 'std::unordered_map' is defined in header '<unordered_map>'; did you forget to '#include <unordered_map>'?
    2 | #include <unordered_set>
  +++ |+#include <unordered_map>
    3 | 
input/code.cpp:5:53: error: expected ',' or '...' before '<' token
    5 | void add_friends(int pupil, const std::unordered_map<int, std::unordered_set<int>> &friendships, std::unordered_set<int>& group_friends){
      |                                                     ^
input/code.cpp: In function 'void add_friends(int, int)':
input/code.cpp:6:8: error: 'group_friends' was not declared in this scope; did you mean 'add_friends'?
    6 |     if(group_friends.contains(pupil)){
      |...

Code

#include <iostream>
#include <unordered_set>


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";

}