Submission #937151

# Submission time Handle Problem Language Result Execution time Memory
937151 2024-03-03T14:32:10 Z amirhoseinfar1385 Harbingers (CEOI09_harbingers) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn=100000+10;
long long inf=1e18,kaf=(1<<17);
struct func{
	func(){
		fas=shib=-inf;
	}
	long long fas,shib;
	long long inersect(func f){
		long long sor=fas-f.fas,makh=f.shib-shib;
		if(makh==0){
			if(sor>0){
				return -inf;
			}
			return inf;
		}
		if(makh<0){
			makh*=-1;
			sor*=-1;
		}
		if(sor<0){
			return sor/makh;
		}
		return (sor+makh-1)/makh;
	}
	bool operator <(const func f)const {
		return shib<f.shib;
	}
}fakefunc;
struct cht{
	vector<pair<long long,func>>st;
	void add(func f){
		while((int)st.size()>0){
			int x=f.inersect(st.back().second);
			if(x<=st.back().first){
				st.pop_back();
				continue;
			}else{
				st.push_back(make_pair(x,f));
				break;
			}
		}
		if((int)st.size()==0){
			st.push_back(make_pair(-inf,f));
		}
	}
	long long get(long long x){
		int p=lower_bound(st.begin(),st.end(),make_pair(x+1,fakefunc))-st.begin()-1;
		if(p<0){
			return -inf;
		}
		return st[p].second.fas+x*st[p].second.shib;
	}
};

struct segment{
	cht ch[(1<<18)];
	void upd(int i,int l,int r,int tl,int tr,func f){
		if(l>r||l>tr||r<tl||tl>tr){
			return ;
		}
		if(l>=tl&&r<=tr){
			ch[i].add(f);
			return ;
		}
		int m=(l+r)>>1;
		upd((i<<1),l,m,tl,tr,f);
		upd((i<<1)^1,m+1,r,tl,tr,f);
	}
	long long pors(int x,int v){
		long long ret=-inf;
		x+=kaf;
		while(x>0){
			ret=max(ret,ch[x].get(v));
			x>>=1;
		}
		return ret;
	}
}seg;

struct yal{
	int u,v,w;
	int getad(int fu){
		return (u^v^fu);
	}
}alle[maxn];
int n,timea=0,high[maxn];
long long dp[maxn];
pair<int,int>stf[maxn],all[maxn];
vector<int>adj[maxn];

void dfs(int u,int par=0,int len=0){
	timea++;
	high[u]=len;
	stf[u].first=timea;
	for(auto x:adj[u]){
		int v=alle[x].getad(u);
		if(v!=par){
			dfs(v,u,len+alle[x].w);
		}
	}
	stf[u].second=timea;
}

void vorod(){
	cin>>n;
	for(int i=0;i<n-1;i++){
		cin>>alle[i].u>>alle[i].v>>alle[i].w;
		adj[alle[i].u].push_back(i);
		adj[alle[i].v].push_back(i);
	}
	for(int i=2;i<=n;i++){
		cin>>all[i].first>>all[i].second;
	}
}

void pre(){
	dfs(1);
}

void upd(int u){
	dp[u]=1ll*min(-seg.pors(stf[u].first,all[u].second),0ll)+all[u].first+1ll*all[u].second*high[u];
	func f;
	f.fas=-dp[u];
	f.shib=high[u];
	seg.upd(1,0,kaf-1,stf[u].first,stf[u].second,f);
}

void solve(int u=1,int para){
	upd(u);
	for(auto x:adj[u]){
		int v=alle[x].getad(u);
		if(v!=para){
			solve(v,u);
		}
	}
}

void khor(){
	for(int i=2;i<=n;i++){
		cout<<dp[i]<<" ";
	}
	cout<<"\n";
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	//cout.tie(0);
	//freopen("inp.txt","r",stdin);
	vorod();
	pre();
	solve();
	khor();
}

Compilation message

harbingers.cpp:130:24: error: default argument missing for parameter 2 of 'void solve(int, int)'
  130 | void solve(int u=1,int para){
      |                    ~~~~^~~~
harbingers.cpp:130:16: note: ...following parameter 1 which has a default argument
  130 | void solve(int u=1,int para){
      |            ~~~~^~~