Submission #1140916

#TimeUsernameProblemLanguageResultExecution timeMemory
1140916why1Race (IOI11_race)C++20
Compilation error
0 ms0 KiB
//#include "race.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long 
#define pii pair<ll,ll>
#define fi first
#define se second
#define sz size()
#define pb push_back

const int N = 2e5;

int n,k;
int h[N+1][2],l[N+1];

vector<pii> g[N+1];
ll dw[N+1],d[N+1];
set<pii> st[N+1];
ll ans=1e9;

void calc(int v,int pr){
	for(auto [to,i]: g[v]){
		if(to!=pr){
			dw[to]=dw[v]+l[i];
			d[to]=d[v]+1;
			calc(to,v);
		}
	}
}

void dfs(int v,int pr){	
	st[v].insert({dw[v],v});
	for(auto [to,i]: g[v]){
		if(to!=pr){
			dfs(to,v);	
			if(st[v].sz<st[to].sz)
				st[v].swap(st[to]);
			for(auto [D,j]: st[to]){
				ll x=k+2*dw[v]-D;	
				auto it=st[v].lower_bound({x,0});
				if(it!=st[v].end() && it->fi==x){
					ans=min(ans,d[j]+d[it->se]-2*d[v]);
				}
			}
			for(auto j: st[to]){
				st[v].insert(j);
			}
		}
	}
}

int best_path(int n, int k, int h[][2], int l[])
//void solve(){

	//cin>>n>>k;
	for(int i = 1; i <= n-1; i++){
		//cin>>h[i][0]>>h[i][1]>>l[i];
		h[i][0]++,h[i][1]++;
		g[h[i][0]].pb({h[i][1],i});
		g[h[i][1]].pb({h[i][0],i});
	}

	calc(1,-1);
	dfs(1,-1);
/*
	for(int i = 1; i <= n; i++){
		cout<<i<<": ";
		for(auto j: st[i]){
			cout<<"{"<<j.fi<<" "<<j.se<<"} ";
		}
		cout<<"\n";
	}
*/
	if(ans==1e9)
		ans=-1;
	//cout<<ans<<"\n";
	return ans;
}
/*
int main(){
	solve();
	return 0;
}
*/

Compilation message (stderr)

race.cpp:57:9: error: expected initializer before 'for'
   57 |         for(int i = 1; i <= n-1; i++){
      |         ^~~
race.cpp:57:24: error: 'i' does not name a type; did you mean 'fi'?
   57 |         for(int i = 1; i <= n-1; i++){
      |                        ^
      |                        fi
race.cpp:57:34: error: 'i' does not name a type; did you mean 'fi'?
   57 |         for(int i = 1; i <= n-1; i++){
      |                                  ^
      |                                  fi
race.cpp:64:13: error: expected constructor, destructor, or type conversion before '(' token
   64 |         calc(1,-1);
      |             ^
race.cpp:65:12: error: expected constructor, destructor, or type conversion before '(' token
   65 |         dfs(1,-1);
      |            ^
race.cpp:75:9: error: expected unqualified-id before 'if'
   75 |         if(ans==1e9)
      |         ^~
race.cpp:78:9: error: expected unqualified-id before 'return'
   78 |         return ans;
      |         ^~~~~~
race.cpp:79:1: error: expected declaration before '}' token
   79 | }
      | ^