Cod sursa(job #1377409)

Utilizator supremusChihalau Andrei supremus Data 5 martie 2015 21:35:55
Problema Stramosi Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.41 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("muchii.txt");
ofstream g("da.txt");
using namespace std;

int n,m,i,q,p,t[20],x;
int main()
{
    f>>n;
    f>>m;
    for(i=1;i<=n;i++)
      {   f>>x;
        t[i]=x;
      }
    for(i=1;i<=m;i++)
    {
        f>>q;f>>p;
        while(p)
        {
            p--;
            q=t[q];
        }
        g<<q<<endl;
    }
}