Submission #944912

#TimeUsernameProblemLanguageResultExecution timeMemory
944912PenguinsAreCuteStations (IOI20_stations)C++17
76 / 100
611 ms1652 KiB
#include "stations.h" #include <bits/stdc++.h> using namespace std; #define MAXN 1005 vector<int> a[MAXN]; int pre[MAXN], post[MAXN], h[MAXN]; int c; void dfs(int x, int p) { if(h[x]&1) pre[x] = c++; for(auto i: a[x]) if(i != p) {h[i] = h[x] + 1; dfs(i, x);} if(!(h[x]&1)) pre[x] = (c++); } std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) { c = 0; h[0] = 0; for(int i = 0; i < MAXN; i++) a[i].clear(); std::vector<int> labels(n); for(int i = 0; i < n - 1; i++) { a[u[i]].push_back(v[i]); a[v[i]].push_back(u[i]); } dfs(0, -1); for (int i = 0; i < n; i++) labels[i]=pre[i]<<1|(h[i]&1); return labels; } int find_next_station(int s, int t, std::vector<int> c) { if(s & 1) { if(t < s) return end(c)[-1]; auto it = lower_bound(c.begin(),c.end(),t&(-2)); if(it == c.end()) return end(c)[-1]; return (*it); } else { if(t > s) return c[0]; auto it = upper_bound(c.begin(),c.end(),t|1); if(it == c.begin()) return c[0]; return (*(--it)); } }
#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...