Cod sursa(job #2170951)

Utilizator KrosomAngelo Barbu Krosom Data 15 martie 2018 10:31:52
Problema Cerere Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 kb
///Bodak Yellow actually sucks. No offence, lads.
#include <fstream>
#define DIM 100005

using namespace std;

ifstream f("cerere.in");
ofstream g("cerere.out");

int Offset, nr, career;
int CardiB[DIM], CardiBronx[DIM];

int BodakYellow(int bodak, int yellow)
{
    if (!CardiBronx[bodak])
        return nr;
    career=bodak;
    while (yellow)
    {
        yellow--;
        career=CardiB[career];
    }
    nr++;
    BodakYellow(career, CardiBronx[career]);
}

int main()
{
    int fame1, fame2;
    f>>Offset;
    for (int Migos=1; Migos<=Offset; Migos++)
        f>>CardiBronx[Migos];
    for (int Migos=1; Migos<=Offset; Migos++)
    {
        f>>fame1>>fame2;
        CardiB[fame2]=fame1;
    }
    for (int Migos=1; Migos<=Offset; Migos++)
    {
        nr=0;
        g<<BodakYellow(Migos, CardiBronx[Migos])<<" ";
    }
    g<<"\n";
    f.close();
    g.close();
    return 0;
}