#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("cerere.in");
ofstream fout("cerere.out");
int n, t[100005], str[100005], k[100005];
void citire() {
fin >> n;
for(int i = 1; i <= n; i++)
fin >> k[i];
for(int i = 1; i < n; i++) {
int x, y;
fin >> x >> y;
t[y] = x;
}
}
void solve() {
for(int i = 1; i <= n; i++) {
str[i] = i;
for(int j = 1; j <= k[i]; j++)
str[i] = t[str[i]];
}
for(int i = 1; i <= n; i++) {
int x = i, nr = 0;
while(k[x]) {
x = str[x];
nr++;
}
fout << nr << ' ';
}
}
int main() {
citire();
solve();
}