#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
using vi = vector<int>;
using pi = pair<int, int>;
using vl = vector<ll>;
#define iter(x) begin(x), end(x)
const int N = 3e5 + 5;
vi e[N];
ll a[N], b[N];
int root[N];
int find(int k){
    return root[k] == -1 ? k : (root[k] = find(root[k]));
}
ll dp[N][3]; // 0 = dist+0, 1 = dist+1, 2 = dist-1; 
vi aux[N];
ll depth[N];
int par[N];
ll weight_m1[N];
void build(int k, int p=-1){
    dp[k][0] = a[k] - b[k] * (depth[k] + 1);
    dp[k][2] = -1e18;
    weight_m1[k] = a[k] - b[k] * (depth[k] - 1);
    par[k] = p;
    for(int j : e[k]){
        if(j == p) continue;
        depth[j] = depth[k] + 1;
        build(j, k);
        dp[k][0] = max(dp[k][0], dp[j][0]);
        weight_m1[k] = max(weight_m1[k], weight_m1[j]);
    }
}
int n,m;
void push_all(){
    vi all(n);
    iota(iter(all), 1);
    sort(iter(all), [&](int a, int b){
        return depth[a] > depth[b];
    });
    for(int k : all){
        for(int j : aux[k]){
            if(depth[j] < depth[k]){
                dp[k][0] = max(dp[k][0], dp[j][0]);
                dp[k][2] = max(dp[k][2], dp[j][2]);
            }
        }
        for(int j : aux[k]){
            if(depth[j] == depth[k]){
                dp[k][2] = max(dp[k][2], weight_m1[j]);
            }
        }
    }
}
int main() {
    ios::sync_with_stdio(false); cin.tie(0); 
    memset(root, -1, sizeof root);
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        cin >> a[i] >> b[i];
    }
    for(int i = 1; i < n; i++){
        int u,v;
        cin >> u >> v;
        int ru = find(u), rv = find(rv);
        if(ru != rv){
            e[u].push_back(v);
            e[v].push_back(u);
        }else{
            aux[u].push_back(v);
            aux[v].push_back(u);
        }
    }
    build(1);
    push_all();
    for(int i = 1; i <= n; i++){
        cout << i << ' ' << dp[i][0] << ' ' << dp[i][2] << endl;
        if(depth[i] == 1) { // connected to 1
            ll ans = max(dp[i][0], dp[i][2]);
            // cout << ans << '\n';
        }   
    }
}
