Submission #832861

#TimeUsernameProblemLanguageResultExecution timeMemory
832861HorizonWestSplit the Attractions (IOI19_split)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

vector <vector<int>> v;
vector <int> g, p1, ans, pass;

int last(int node)
{
    p1[node] = 1;
    for(auto& u : v[node])
        if(!p1[node]) return last(u);
    return node;
}

void dfs(int node, int& cont, int& group)
{
    ans[node] = group; cont++;
    if(cont == g[group])
    {
        cont = 0;
        group = max(1, (group + 1) % 4);
    }
    pass[node] = 1;
    for(auto& u : v[node])
    {
        if(!pass[u])
        {
            dfs(u, cont, group);
        }
    }

    return;
}

vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q)
{
    int m = p.size(); ans.assign(n, 3); pass.assign(n, 0);

    v.assign(n + 1, vector <int> ());
    vector <bool> subtask(5, 1);

    for(int i = 0; i < m; i++)
    {
        v[p[i]].push_back(q[i]);
        v[q[i]].push_back(p[i]);

        if(v[p[i]].size() > 2) subtask[0] = false;
        if(v[q[i]].size() > 2) subtask[0] = false;
    }

    //if(subtask[0])
    //{
        p1.assign(n, 0); g.assign(4, 0);
        g[1] = a; g[2] = b; g[3] = c;
        dfs(last(0), 0, 2);
        return ans;
    //}

	return ans;
}

Compilation message (stderr)

split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:55:22: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
   55 |         dfs(last(0), 0, 2);
      |                      ^
split.cpp:15:25: note:   initializing argument 2 of 'void dfs(int, int&, int&)'
   15 | void dfs(int node, int& cont, int& group)
      |                    ~~~~~^~~~