Submission #596212

#TimeUsernameProblemLanguageResultExecution timeMemory
596212FatihSolakHighway Tolls (IOI18_highway)C++17
0 / 100
220 ms262144 KiB
#include "highway.h" #include <bits/stdc++.h> #define N 100005 using namespace std; vector<pair<int,int>> adj[N]; int par[N]; int paredge[N]; int dep[N]; vector<int> w; void dfs(int v,int pr,int edge){ //cout << v << " " << pr << " " << edge << endl; par[v] = pr; paredge[v] = edge; for(auto u:adj[v]){ if(u.first == pr)continue; dep[u.first] = dep[v] + 1; dfs(u.first,v,u.second); } } void dfs2(int v,int pr){ w[paredge[v]] = 1; for(auto u:adj[v]){ if(u.first == pr)continue; dfs2(u.first,v); } } vector<int> xx; void dfs3(int v,int pr,int target){ if(dep[v] == target) xx.push_back(v); for(auto u:adj[v]){ if(u.first == pr)continue; dfs3(u.first,v,target); } } void find_pair(int n, vector<int> u, vector<int> v, int a, int b) { int m = u.size(); for(int i = 0;i<m;i++){ adj[u[i]].push_back({v[i],i}); adj[v[i]].push_back({u[i],i}); } w.assign(m,0); long long len = ask(w) / a; vector<int> x; for(int i = 0;i<m;i++){ x.push_back(i); } while(x.size() > 1){ vector<int> tmp; while(tmp.size() < x.size()){ tmp.push_back(x.back()); x.pop_back(); } w.assign(m,0); for(auto u:tmp){ w[paredge[u]] = 1; } if(ask(w) != len * a){ x = tmp; } } int root = u[x[0]]; //cout << root << endl; dfs(root,-1,-1); w.assign(m,0); dfs2(v[x[0]],root); int dep1 = (ask(w) - len*a) / (b-a); int dep2 = len - dep1; int s = -1,t = -1; if(dep1 == 0)s = root; if(dep2 == 0)t = root; //cout << dep1 << " " << dep2 << endl; if(s == -1){ xx.clear(); dfs3(v[x[0]],root,dep1); while(xx.size() > 1){ vector<int> tmp; while(tmp.size() < xx.size()){ tmp.push_back(xx.back()); xx.pop_back(); } w.assign(m,0); for(auto u:tmp){ w[paredge[u]] = 1; } if(ask(w) != len * a){ xx = tmp; } } s = xx[0]; } if(t == -1){ xx.clear(); for(auto u:adj[root]){ if(u.first == v[x[0]])continue; dfs3(u.first,root,dep2); } while(xx.size() > 1){ vector<int> tmp; while(tmp.size() < xx.size()){ tmp.push_back(xx.back()); xx.pop_back(); } w.assign(m,0); for(auto u:tmp){ w[paredge[u]] = 1; } if(ask(w) != len * a){ xx = tmp; } } t = xx[0]; } 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...