Submission #959045

#TimeUsernameProblemLanguageResultExecution timeMemory
959045The_SamuraiStations (IOI20_stations)C++17
52.32 / 100
600 ms1512 KiB
#include "stations.h" #include "bits/stdc++.h" using namespace std; std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) { vector<vector<int>> adj(n); vector<bool> vis(n); for (int i = 0; i < n - 1; i++) { adj[u[i]].emplace_back(v[i]); adj[v[i]].emplace_back(u[i]); } int z = 0; vector<int> tin(n), tout(n), ans(n); auto dfs = [&](auto &dfs, int u) -> void { tin[u] = tout[u] = z++; vis[u] = true; for (int v: adj[u]) { if (vis[v]) continue; dfs(dfs, v); tout[u] = tout[v]; } }; dfs(dfs, 0); for (int i = 0; i < n; i++) ans[i] = tin[i] * 1000 + tout[i]; // cout << '\t'; // for (int i = 0; i < n; i++) cout << tin[i] << ' '; // cout << endl; // for (int i = 0; i < n - 1; i++) cout << tin[u[i]] << ' ' << tin[v[i]] << endl; return ans; } bool is_par(int v1, int v2) { int tin1 = v1 / 1000, tout1 = v1 % 1000; int tin2 = v2 / 1000, tout2 = v2 % 1000; return tin1 <= tin2 and tout2 <= tout1; } int find_next_station(int s, int t, std::vector<int> c) { // cout << '\t' << s << ' ' << t << endl; // cout << '\t'; // for (int x: c) cout << x << ' '; // cout << endl; for (int u: c) { if (is_par(s, u) and is_par(u, t)) return u; } for (int u: c) { if (is_par(u, s)) return u; } }

Compilation message (stderr)

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:49:1: warning: control reaches end of non-void function [-Wreturn-type]
   49 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...