Cod sursa(job #2626605)

Utilizator darkeagleDaniel Popescu darkeagle Data 7 iunie 2020 02:59:24
Problema Cerere Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <bits/stdc++.h>

using namespace std;


int n;
int v[100001], g[100001];
void citire() {

    freopen("cerere.in", "r", stdin);
    freopen("cerere.out", "w", stdout);

    scanf("%d",&n);

    int i, j;

    for(i = 1; i <= n ;i++) {
        scanf("%d",&v[i]);
    }

    int x;
    int y;
    for(i=1;i<=n;i++) {

        scanf("%d %d",&x,&y);
        g[y] = x;
    }

}
int str(int t1) {

if(v[t1] == 0)
    return 0;


int r, nr1;

int h;
int nr2 = 0;

h = t1;
do{

   nr1 = 0;


while(nr1 < v[t1])
{

    r = g[h];
    h = r;
    nr1++;
}
nr2++;


} while(v[h] != 0);

return nr2;
}

int main()
{

    citire();
   // cout<<str(7) << endl;

 int i, x;
 for(i=1;i<=n;i++)
 {
     x = str(i);

     printf("%d ",x);


 }
   /*  for(i=1;i<=n;i++) {

        nr = 0;
        if(v[i] == 0)
            g1[i] = 0;
        else
        {
            int h, r, r1, r2;

            r = i;

             g1[i] = g1[str(i)] + 1;

        }
    }

    for(i=1;i<=n;i++) {


        printf("%d ",g1[i]);
    }

*/
    return 0;
}