Submission #412511

#TimeUsernameProblemLanguageResultExecution timeMemory
412511two_sidesStations (IOI20_stations)C++17
Compilation error
0 ms0 KiB
#include "stations.h" #include <bits/stdc++.h> using namespace std; void dfs(int u, int p, bool d, int &cnt, const vector <vector <int>> &adj, vector <int> &label) { if (!d) label[u] = cnt++; for (int v : adj[u]) if (v != p) dfs(v, u, !d, adj, label); if (d) label[u] = cnt++; } vector <int> label(int n, int k, vector <int> u, vector <int> v) { vector <vector <int>> adj(n); vector <int> label(n); for (int i = 0; i + 1 < n; i++) { adj[u[i]].push_back(v[i]); adj[v[i]].push_back(u[i]); } int cnt = 0; dfs(0, -1, 0, cnt, adj, label); return label; } int find_next_station(int s, int t, vector <int> c) { if (s < c[0]) { int lo = s, hi = c.size() > 1 ? c[c.size() - 2] : s; if (lo <= t && t <= hi) { for (int u : c) if (u >= t) return u; } return c[c.size() - 1]; } else { int hi = s, lo = c.size() > 1 ? c[1] : s; if (lo <= t && t <= hi) { for (int u : c) if (u <= t) return u; } return c[0]; } return c[0]; }

Compilation message (stderr)

stations.cpp: In function 'void dfs(int, int, bool, int&, const std::vector<std::vector<int> >&, std::vector<int>&)':
stations.cpp:9:35: error: invalid initialization of reference of type 'int&' from expression of type 'const std::vector<std::vector<int> >'
    9 |         if (v != p) dfs(v, u, !d, adj, label);
      |                                   ^~~
stations.cpp:6:37: note: in passing argument 4 of 'void dfs(int, int, bool, int&, const std::vector<std::vector<int> >&, std::vector<int>&)'
    6 | void dfs(int u, int p, bool d, int &cnt, const vector <vector <int>> &adj, vector <int> &label) {
      |                                ~~~~~^~~