제출 #620725

#제출 시각아이디문제언어결과실행 시간메모리
6207258e7기지국 (IOI20_stations)C++17
54.96 / 100
1083 ms788 KiB
//Challenge: Accepted #include <bits/stdc++.h> using namespace std; #ifdef zisk void debug(){cout << endl;} template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);} template<class T> void pary(T l, T r){ while (l != r) cout << *l << " ", l++; cout << endl; } #else #define debug(...) 0 #define pary(...) 0 #endif #define ll long long #define maxn 1000 #define pii pair<int, int> #define ff first #define ss second #include "stations.h" const int mul = 501; vector<int> adj[maxn]; int in[maxn], out[maxn], siz[maxn]; int tin, tout; void getsiz(int n, int par) { siz[n] = 1; for (int v:adj[n]) { if (v != par) { getsiz(v, n); siz[n] += siz[v]; } } } int getcentroid(int n, int par, int tot) { for (int v:adj[n]) { if (v != par && siz[v] * 2 > tot) { return getcentroid(v, n, tot); } } return n; } void dfs(int n, int par) { in[n] = tin++; siz[n] = 1; for (int v:adj[n]) { if (v != par) { dfs(v, n); siz[n] += siz[v]; } } out[n] = tout++; } std::vector<int> label(int n, int LIM, std::vector<int> U, std::vector<int> V) { vector<int> ret(n); for (int i = 0;i < n;i++) { adj[i].clear(); in[i] = 0, out[i] = 0; siz[i] = 0; } tin = tout = 0; for (int i = 0;i < n - 1;i++) { adj[U[i]].push_back(V[i]); adj[V[i]].push_back(U[i]); } getsiz(0, -1); int root = getcentroid(0, -1, n); dfs(root, -1); for (int i = 0; i < n; i++) { ret[i] = in[i] * mul + siz[i] +1; } ret[root] = 0; return ret; } const int inf = 1e9; int find_next_station(int s, int t, std::vector<int> c) { int is, os, it, ot; if (s == 0) { is = 0, os = inf; } else { s--; is = s/mul; os = is + s%mul; } if (t == 0) { it = 0, ot = inf; } else { t--; it = t/mul; ot = it + t %mul; } if (is <= it && ot <= os) { //subtree for (int v:c) { if (v==0) continue; v--; int iv = v/mul, ov = iv + v%mul; if (iv > is && iv <= it && ot <= ov) return v+1; } } else { for (int v:c) { v--; if (v/maxn < is) return v+1; } } return 0; }
#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...