# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
394387 | Theo830 | Highway Tolls (IOI18_highway) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll INF = 1e18+7;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
#include "highway.h"
ll par[90005] = {0};
ll dep[90005] = {0};
vector<vll>adj;
void dfs(ll u,ll p){
par[u] = p;
for(auto x:adj[u]){
if(x != p){
depth[x] = depth[u] + 1;
dfs(x,u);
}
}
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
adj.assign(N+1,vll());
ll m = U.size();
f(i,0,m){
adj[U[i]].pb(V[i]);
adj[V[i]].pb(U[i]);
}
dfs(0,-1);
ll s = 0,t;
vector<int>w(m);
w.assign(m,0);
ll ans = ask(w);
ll di = ans;
ll de = 0;
f(i,0,m){
ll x = U[i];
if(par[V[i]] == U[i]){
x = V[i];
}
w[x] = 1;
if(ask(w) != di){
if(depth[x] > de){
de = depth[x];
t = x;
}
}
w[x] = 0;
}
answer(s,t);
}