求告知错误原因或hack
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+10;
int a[N],b[N],c[N];
int t[N],h[N];
bool book[N];
vector<int> g[N];
int n;
void dfs(int x,int fa)
{
book[x]=0;
h[x]=t[x];
for(int to:g[x])
{
if(to==fa) continue;
dfs(to,x);
h[x]=min(h[x],h[to]-1);
}
}
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > q;
bool check(int mid)
{
for(int i=1;i<=n;i++)
{
int l=1,r=mid;
t[i]=-1;
while(l<=r)
{
int k=(l+r)>>1;
int y=c[i]>=0?mid:(floorl(1.0*(1-b[i])/c[i]));
__int128 tmp=c[i];
tmp*=(k+y)*(y-k+1)/2;
tmp+=b[i]*(y-k+1);
tmp+=mid-y;
if(tmp>=a[i])
{
t[i]=k;
l=k+1;
}
else
r=k-1;
}
if(t[i]==-1)
return 0;
}
dfs(1,0);
while(q.size()) q.pop();
q.push(make_pair(h[1],1));
int cnt=1;
while(q.size())
{
int x=q.top().second;
q.pop();
book[x]=1;
if(t[x]<cnt)
return 0;
cnt++;
for(int i:g[x])
{
if(book[i]) continue;
q.push(make_pair(h[i],i));
}
}
return 1;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i]>>b[i]>>c[i];
for(int i=1;i<n;i++)
{
int x,y;
cin>>x>>y;
g[x].push_back(y);
g[y].push_back(x);
}
int l=1,r=1e9,ans;
while(l<=r)
{
int mid=(l+r)>>1;
if(check(mid))
{
r=mid-1;
ans=mid;
}
else
l=mid+1;
}
cout<<ans;
return 0;
}