Pagini recente » Cod sursa (job #2648535) | Cod sursa (job #703167) | Cod sursa (job #2764909) | Cod sursa (job #3134545) | Cod sursa (job #1234200)
#include<fstream>
#include<vector>
using namespace std;
ifstream in("cerere.in");
ofstream out("cerere.out");
const int nmax = 100006;
int v[nmax], n, vrasp[nmax], sps[nmax], rps[nmax], chestie, ac;
vector <int> tati[nmax];
void dfs( int x ) {
sps[++chestie] = x;
if(v[x]!=0 )
vrasp[x] = vrasp[sps[chestie - v[x]]] + 1;
for (int i = 0; i<(int)tati[x].size(); i++)
{
dfs(tati[x][i]);
chestie--;
}
}
int main(){
int player_unu=0;
in>>n;
for(int i = 1; i<=n; i++)
{
in>>v[i];
}
for(int i = 1; i<=n - 1; i++)
{
int x, y;
in>>x>>y;
tati[x].push_back(y);
rps[y]++;
}
for(int i = 1; i<=n; i++)
{
if(rps[i]==0)
{
ac = i;
break;
}
}
dfs(ac);
for(int i = 1; i<=n; i++)
{
out<<vrasp[i]<<' ';
}
return player_unu;
}