Cod sursa(job #1060737)

Utilizator mvcl3Marian Iacob mvcl3 Data 18 decembrie 2013 17:15:14
Problema Cerere Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <fstream>

#define in "cerere.in"
#define out "cerere.out"
#define Max_Size 100009

std :: ifstream f(in);
std :: ofstream g(out);

int N;
int A[Max_Size], Tata[Max_Size];

inline void Read_Data()
{
    f >> N;

    for(int i = 1; i <= N; ++i)
        f >> A[i];

    for(int a, b, i = 1; i <= N; ++i)
    {
        f >> a >> b;

        Tata[b] = a;
    }
}

inline int Rad(int node)
{
    int k = A[node];

    int rez = 0;

    if(!A[node]) return 0;

    bool ok = 1;
    int node1 = node;

    do
    {
        k = A[node];
        while(k && node1 > 1)
        {
            node1 = Tata[node1];
            --k;
        }
        if(!A[node1])   ok = 0;
        ++rez;
    }
    while(ok);

    return rez;
}

inline void Solve()
{
    for(int i = 1; i <= N; ++i)
        g << Rad(i) << ' ';
}

int main()
{
    Read_Data();
    Solve();

    g.close();
    return 0;
}