#include<bits/stdc++.h>
using namespace std;
namespace zzt
{
const int N=2e6+3;
#define ll long long
int n,b[N],c[N],ans,cnt,head[N],vis[N],ti,fa[N],skp[N],p[N];
ll a[N];
struct node{
int to,nex;
}e[N*2];
struct xxx{
int id,tim;
}t[N];
void add(int x,int y)
{
e[++cnt]=(node){y,head[x]};
head[x]=cnt;
}
bool cmp(xxx a,xxx b)
{
return a.tim<b.tim;
}
void dfs(int u,int p1)
{
fa[u]=p1;
for(int i=head[u];i;i=e[i].nex)
{
int v1=e[i].to;
if(v1==p1) continue;
dfs(v1,u);
}
}
int getnum(int id1,int limit,int top)
{
int tot;
if(c[id1]>=0)
{
tot=b[id1]*(top-limit+1)+c[id1]*(top+limit)*(top-limit+1)/2;
if(tot>=a[id1]) return 1;
else return 0;
}
else
{
int temp=(1-b[id1])/c[id1];
if(temp<limit)
tot=top-limit+1;
else if(temp>=limit&&temp<=top)
tot=b[id1]*(temp-limit+1)+c[id1]*(temp+limit)*(temp-limit+1)/2+top-temp;
else if(temp>top)
tot=b[id1]*(top-limit+1)+c[id1]*(top+limit)*(top-limit+1)/2;
if(tot>=a[id1]) return 1;
else return 0;
}
}
bool check(int x)
{
for(int i=1;i<=n;i++)
vis[i]=0;
for(int i=1;i<=n;i++)
{
int temp1;
int dl=1,dr=n;
while(dl<=dr)
{
int midd=(dl+dr)/2;
if(getnum(i,midd,x)) dl=midd+1,temp1=midd;
else dr=midd-1;
}
t[i].tim=temp1;t[i].id=i;
}
sort(t+1,t+n+1,cmp);
for(int i=1;i<=n;i++)
p[t[i].id]=i;
ti=0;
for(int i=1;i<=n;i++)
{
int top1=0;
int v=t[i].id;
while(!vis[v])
{
vis[v]=1;
skp[++top1]=p[v];
v=fa[v];
}
while(top1) if(t[skp[top1--]].tim<++ti) return 0;
}
return 1;
}
int Main()
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i]>>b[i]>>c[i];
for(int i=1;i<n;i++)
{
int u1,v1;
cin>>u1>>v1;
add(u1,v1);add(v1,u1);
}
vis[0]=1;dfs(1,0);int l=n,r=1e9;
while(l<=r)
{
int mid=(l+r)/2;
if(check(mid)) r=mid-1,ans=mid;
else l=mid+1;
}
printf("%d",ans);
return 0;
}
}
int main()
{
return zzt::Main();
}