Pagini recente » Cod sursa (job #2787229) | Cod sursa (job #2965599) | Cod sursa (job #1690921) | Cod sursa (job #744135) | Cod sursa (job #2360096)
#include <fstream>
#include <algorithm>
#define DIM 100000
using namespace std;
ifstream in("cerere.in");
ofstream out("cerere.out");
int n;
int k[DIM + 5], parent[DIM];
vector<int> children[DIM];
int main()
{
in>>n;
for( int i = 1; i <= n; i++ )
in>>k[i];
for( int i = 1; i < n; i++ )
{
int from, to; in>>from>>to;
children[from].push_back(to);
parent[to] = from;
}
for( int i = 1; i <= n; i++ )
{
int current_node = i;
int solution = 0;
while( k[current_node] != 0 )
{
int step_back = k[current_node];
while( step_back != 0 )
{
step_back--;
current_node = parent[current_node];
}
solution++;
}
out<<solution<<" ";
}
return 0;
}