Submission #367303

#TimeUsernameProblemLanguageResultExecution timeMemory
367303PurpleCrayonStations (IOI20_stations)C++17
5 / 100
1123 ms1236 KiB
#include "stations.h" #include <bits/stdc++.h> using namespace std; #define sz(v) int(v.size()) int tt; vector<int> ans; vector<vector<int>> adj; void dfs(int c=0, int p=-1, bool b=0){ if (!b) ans[c] = tt++; for (auto nxt : adj[c]) if (nxt != p) dfs(nxt, c, b^1); if (b) ans[c] = tt++; } vector<int> label(int n, int k, vector<int> u, vector<int> v) { ans.assign(n, -1), adj.assign(n, vector<int>()), tt=0; for (int i = 0; i < n-1; i++) adj[u[i]].push_back(v[i]), adj[v[i]].push_back(u[i]); dfs(); return ans; } int find_next_station(int s, int t, vector<int> c) { if (s == 0){ //ans for the root for (auto nxt : c) if (nxt >= t) return nxt; assert(false); } bool b=s>c[0]; if (b){ //i'm postorder int p = c[0]; if (sz(c) == 1 || t < c[1] || t > s) return p; int ans=-1; for (auto nxt : c) if (nxt != p) { if (nxt <= t) ans = nxt; } assert(ans != -1); return ans; } else { //i'm preorder int p = c[sz(c)-1]; if (sz(c) == 1 || t < s || t >= c[sz(c)-1]) return p; int ans=-1; for (auto nxt : c) if (nxt != p) { if (nxt >= t){ return nxt; } } assert(false); } }

Compilation message (stderr)

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:48:13: warning: unused variable 'ans' [-Wunused-variable]
   48 |         int ans=-1;
      |             ^~~
#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...