#include<bits/stdc++.h>
#define int long long
using namespace std;
namespace wxh666{
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#define sqrt(a) __builtin_sqrt(a)
#define f(a,b,c) for(int a=b;a<=c;a++)
#define ff(a,b,c) for(int a=b;a>=c;a--)
#define g(n) f(i,1,n)
#define df(n,m) g(n) f(j,1,m)
#define max max_by_wxh
template<typename T>
inline T max_by_wxh(T x,T y) {return ((x)>(y)?(x):y);}
template<typename T,typename ...Args>
inline T max_by_wxh(T x,Args ...xs) {return max_by_wxh(x,max_by_wxh(xs...));}
#define min min_by_wxh
template<typename T>
inline T min_by_wxh(T x,T y) {return ((x)<(y)?(x):y);}
template<typename T,typename ...Args>
inline T min_by_wxh(T x,Args ...xs) {return min_by_wxh(x,min_by_wxh(xs...));}
template<typename T,typename ...Args>
inline T chkmax(T &x,Args ...xs) {return x=max(x,xs...);}
template<typename T,typename ...Args>
inline T chkmin(T &x,Args ...xs) {return x=min(x,xs...);}
template<typename T>
inline void read(T &ans)
{
char ch=getchar();int f=1;ans=0;
for(;!isdigit(ch);ch=getchar()) ch=='-'?f=-1:f=1;
for(;isdigit(ch);ch=getchar()) ans=(ans<<3)+(ans<<1)+(ch&15);
ans*=f;
return;
}
template<typename T,typename ...Args>
inline void read(T &tmp,Args &...tmps){read(tmp);read(tmps...);}
inline int read()
{
char ch=getchar();int f=1,ans=0;
for(;!isdigit(ch);ch=getchar()) ch=='-'?f=-1:f=1;
for(;isdigit(ch);ch=getchar()) ans=(ans<<3)+(ans<<1)+(ch&15);
return f*ans;
}
#define in read()
template<typename T>
inline void pu(T x)
{
ios::sync_with_stdio(false);
cout<<x;
ios::sync_with_stdio(true);
return;
}
template<typename T>
inline void pk(T x)
{
ios::sync_with_stdio(false);
cout<<x<<" ";
ios::sync_with_stdio(true);
return;
}
inline void pk(char x)
{
ios::sync_with_stdio(false);
cout<<x;
if(x!='\n') cout<<' ';
ios::sync_with_stdio(true);
return;
}
template<typename T,typename ...Args>
inline void pu(T x,Args ...xs){pu(x);pu(xs...);}
template<typename T,typename ...Args>
inline void ppu(T x,Args ...xs){pu(x,xs...,'\n');}
template<typename T,typename ...Args>
inline void pk(T x,Args ...xs){pk(x);pk(xs...);}
template<typename T,typename ...Args>
inline void ppk(T x,Args ...xs){pk(x,xs...,'\n');}
#define cs(dt,n,m) \
for(int i=1;i<=n;i++)\
{\
for(int j=1;j<=m;j++)\
printf("%d ",dt[i][j]);\
cout<<endl;\
}
};using namespace wxh666;
namespace FILES{
#ifdef FILE
string file="";
struct File{File(){freopen((file+".in").c_str(),"r",stdin);freopen((file+".out").c_str(),"w",stdout);}}files;
#endif
};using namespace FILES;
namespace lsq {
typedef int lsqxx;
struct lq {
struct lqbz {
lsqxx v,w,nxt;
} e[1000005];
lsqxx h[1000005],cnt;
inline void add(lsqxx u,lsqxx v,lsqxx w=1) {
e[++cnt].v=v;
e[cnt].w=w;
e[cnt].nxt=h[u];
h[u]=cnt;
}
void erase() {cnt=0;memset(h,0,sizeof(h));return;}
#define F(z,u) for(int j=z.h[u],v=z.e[j].v,w=z.e[j].w;j;j=z.e[j].nxt,v=z.e[j].v,w=z.e[j].w)
}q;
};using namespace lsq;
int n;
struct node{
int a,b,c;
int pos;
void update_pos()
{
if(c>=0) return pos=-1,void();
else return pos=(1-b)/c,void();
}
bool check(int l,int r)
{
if(pos==-1)
{
int len=r-l+1;
if((len*(c*l+c*r+2*b)/2)>=a) return true;
else return false;
}
else
{
int len=r-l+1;
if(r<=pos)
{
if((((b+l*c)+(b+r*c)*len)/2)>=a) return true;
else return false;
}
else if(l<=pos&&r>=pos)
{
if((((b+l*c)+(b+c*pos))*(pos-l+1)/2)+(r-pos)>=a) return true;
else return false;
}
else
{
if(len>=a) return true;
else return false;
}
}
}
}t[100005];
struct nodes{int xh,d,l;}e[100005];
void dfs(int u=1,int fa=1)
{
e[u].d=e[fa].d+1;
F(q,u)
{
if(v==fa) continue;
dfs(v,u);
e[u].l=min(e[u].l,e[v].l);
}
};
bool solve(int x)
{
memset(e,0,sizeof(e));
g(n)
{
if(!t[i].check(1,x)) return false;
int l=1,r=x,ans=0;
while(l<=r)
{
int mid=l+r>>1;
if(t[i].check(mid,x)) ans=mid,l=mid+1;
else r=mid-1;
}
e[i].xh=i;e[i].l=ans;
}
dfs(1,1);
sort(e+1,e+1+n,[&](auto x,auto y){
if(x.l==y.l) return x.d<y.d;
return x.l<y.l;
});
g(n) if(e[i].l<i) return false;
return true;
}
signed main()
{
cin>>n;
g(n)
{
read(t[i].a,t[i].b,t[i].c);
t[i].update_pos();
}
g(n-1)
{
int x,y;read(x,y);
q.add(x,y);q.add(y,x);
}
int l=n,r=1e9,ans=114514;
while(l<=r)
{
int mid=l+r>>1;
if(solve(mid)) ans=mid,r=mid-1;
else l=mid+1;
}
cout<<ans<<endl;
return 0;
}