Submission #816463

#TimeUsernameProblemLanguageResultExecution timeMemory
816463Jarif_RahmanHighway Tolls (IOI18_highway)C++17
51 / 100
214 ms262144 KiB
#include "highway.h" #include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; int n, m; ll A, B; vector<vector<pair<int, int>>> graph; vector<int> depth, p, pe; ll def; void dfs(int nd, int dad, int dad_edge, int d){ p[nd] = dad; depth[nd] = d; pe[nd] = dad_edge; for(auto [x, i]: graph[nd]) if(x != dad) dfs(x, nd, i, d+1); } int find_node(int root){ dfs(root, -1, -1, 0); vector<int> o(n); for(int i = 0; i < n; i++) o[i] = i; sort(o.begin(), o.end(), [&](int a, int b){ return depth[a] > depth[b]; }); ll def = ask(vector<int>(m, 0)); int a = 0, b = n-1; while(a < b){ int md = (a+b)/2; vector<int> w(m, 0); for(int i = 0; i <= md; i++) if(pe[o[i]] != -1) w[pe[o[i]]] = 1; ll x = ask(w); if(x > def) b = md; else a = md+1; } return o[a]; } void find_pair(int _n, vector<int> U, vector<int> V, int _A, int _B){ swap(n, _n); m = U.size(); A = _A, B = _B; graph.resize(n); depth.resize(n); p.resize(n); pe.resize(n, -1); for(int i = 0; i < m; i++){ graph[U[i]].pb({V[i], i}); graph[V[i]].pb({U[i], i}); } def = ask(vector<int>(m, 0)); int s = find_node(0); int t = find_node(s); answer(s, t); }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...