Submission #1083240

# Submission time Handle Problem Language Result Execution time Memory
1083240 2024-09-02T19:06:25 Z Rawlat_vanak Race (IOI11_race) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define speedIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ff first
#define ss second
#define pii pair<ll,ll>
#define pb push_back

vector<vector<pii>> graph;
vector<ll> sz,dist,rep,depth;
vector<bool> removed;
ll n,k,final;

void subtreesize(ll u, ll p){
	sz[u]=1;
	for(pii v:graph[u]){
		if(v.ff==p) continue;
		subtreesize(v.ff,u);
		sz[u]+=sz[v.ff];
	}
}

ll findcentroid(ll u, ll p){
	for(pii v:graph[u]){
		if(removed[v.ff]) continue;
		if(v.ff==p) continue;
		if(2*sz[v.ff]>n){
			return findcentroid(v.ff,u);
		}
	}
	return u;
}


void dfs(ll u, ll p){
	for(pii x:graph[u]){
		ll v=x.ff,w=x.ss;
		if(v==p) continue;
		if(removed[v]) continue;
		rep[v]=rep[u];
		depth[v]=depth[u]+1;
		dfs(v,u);
		dist[v]=dist[u]+w;

	}
}


void centroid_decomp(ll u, ll p){

	
	ll ctrd=findcentroid(u,p);
	//cout<<"hi "<<u<<' '<<p<<' '<<ctrd<<'\n';
	dist.clear();
	dist.resize(n,0);
	rep.clear();
	rep.resize(n);
	depth.clear();
	depth.resize(n,0);
	
	for(pii v:graph[ctrd]){
		if(removed[v.ff]) continue;
		rep[v.ff]=v.ff;
	}
	dfs(ctrd,-1);

	vector<ll> values(k+1,1e7);
	for(ll i=0;i<n;i++){
		if(removed[i]) continue;
		if(dist[i]==0 or depth[i]==0 or dist[i]>k) continue;
		values[dist[i]]=min(values[dist[i]],depth[i]);
	}

	ll ans=1e7;
	values[0]=0;
	for(ll i=0;i<=k;i++){
		if(values[i]==1e7) continue;
		if(values[k-i]!=1e7){
			ans=min(ans,values[i]+values[k-i]);
		}
	}
	final=min(final,ans);




	removed[ctrd]=true;
	for(pii v:graph[ctrd]){
		if(removed[v.ff]) continue;
		centroid_decomp(v.ff,ctrd);
	}

	
}



int best_path(int N, int K, vector<vector<int>> h, vector<int> l){
	n=N,k=K;
	graph.clear();
	graph.resize(n);
	sz.clear();
	sz.resize(n);
	removed.clear();
	removed.resize(n);
	dist.clear();
	dist.resize(n);
	for(ll i=0;i<n-1;i++){
		graph[h[i][0]].pb({h[i][1],l[i]});
		graph[h[i][1]].pb({h[i][0],l[i]});
	}
	final=1e7;
	subtreesize(0,-1);
	centroid_decomp(0,-1);
	if(final==1e7){
		return -1;
	}else{
		return final;
	}


}

Compilation message

/usr/bin/ld: /tmp/cc3qf555.o: in function `main':
grader.cpp:(.text.startup+0x28): undefined reference to `best_path(int, int, int (*) [2], int*)'
collect2: error: ld returned 1 exit status