Submission #559059

#TimeUsernameProblemLanguageResultExecution timeMemory
559059MamedovStations (IOI20_stations)C++17
Compilation error
0 ms0 KiB
#include "stations.h" #include <bits/stdc++.h> using namespace std; /* Label v with tin[v] for even levels and tout[v] for odd levels. This gives us labels of even numbers between [0, 2*n-2]. We can divide each label by 2, so we get all labels in [0, n-1] Note: We can always restore [tin[v], tout[v]] by v and its neighbors' labels. */ vector<vector<int>>g; vector<int>tin, tout; vector<int>labels; int timer; void dfs(int v, int par, int level) { tin[v] = timer++; for (int to : g[v]) { if (to != par) { dfs(to, v, level + 1); } } tout[v] = timer++; if (level % 2 == 0) { labels[v] = tin[v] / 2; } else { labels[v] = tout[v] / 2; } } init (int n) { timer = 0; g.resize(n); tin.resize(n); tout.resize(n); labels.resize(n); for (int i = 0; i < n; ++i) { g[i].clear(); } } vector<int> label(int n, int k, vector<int> u, vector<int> v) { init(n); for (int i = 0; i < n - 1; ++i) { g[u[i]].emplace_back(v[i]); g[v[i]].emplace_back(u[i]); } dfs(0, 0, 0); return labels; } int find_next_station(int s, int t, vector<int> c) { if (c[0] > s) { /// s is labeled with tin[] if (t < s) { return c.back(); } else { auto itr = lower_bound(c.begin(), c.end(), t); if (itr == c.end()) --itr; return (*itr); } } else { /// s is labeled with tout[] if (t > s) { return c[0]; } else { auto itr = upper_bound(c.begin(), c.end(), t); if (itr != c.begin()) --itr; return (*itr); } } }

Compilation message (stderr)

stations.cpp:34:1: error: ISO C++ forbids declaration of 'init' with no type [-fpermissive]
   34 | init (int n) {
      | ^~~~
stations.cpp: In function 'int init(int)':
stations.cpp:43:1: warning: no return statement in function returning non-void [-Wreturn-type]
   43 | }
      | ^