CSES - Aalto Competitive Programming 2024 - wk2 - Mon - Results
Submission details
Task:Building Teams
Sender:fabiank
Submission time:2024-09-09 16:37:09 +0300
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:37:17: error: return-statement with no value, in function returning 'int' [-fpermissive]
   37 |                 return;
      |                 ^~~~~~

Code

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <unordered_set>
#include <unordered_map>

using namespace std;

bool dfs(int pupil, vector<int> &assignments, const vector<vector<int>> &friends, int team);

int main()
{
    int n, m;
    cin >> n >> m;

    vector<vector<int>> friends(n + 1);

    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        friends[a].push_back(b);
        friends[b].push_back(a);
    }

    vector<int> assignments(n + 1, 0);

    for (int pupil = 1; pupil <= n; pupil++)
    {
        if (assignments[pupil] == 0)
        {
            bool result = dfs(pupil, assignments, friends, 1);
            if (result == false)
            {
                cout << "IMPOSSIBLE\n";
                return;
            }
        }
    }

    for (int as : assignments)
    {
        if (as != 0)
        {
            cout << as << " ";
        }
    }
    cout << "\n";
}

bool dfs(int pupil, vector<int> &assignment, const vector<vector<int>> &friends, int team)
{
    int other_team = team == 1 ? 2 : 1;
    assignment[pupil] = team;
    for (int f : friends[pupil])
    {
        int assignment_friend = assignment[f];
        if (assignment_friend == team)
        {
            return false;
        }
        else if (assignment_friend == 0)
        {
            dfs(f, assignment, friends, other_team);
        }
    }
    return true;
}