Cod sursa(job #215926)

Utilizator cvicentiuCiorbaru Vicentiu Marian cvicentiu Data 21 octombrie 2008 19:28:04
Problema Stramosi Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <iostream>
#include <fstream>
using namespace std;
int n,m,q,p,solutie;
int v[250001];
int i,j;
ifstream f ("stramosi.in");
ofstream fout ("stramosi.out");
int citire(){
    f>>n;
    f>>m;
    for (i=1;i<=n;i++){
        f>>v[i];
        }
}

int scriere(int sol){
    fout<<sol<<"\n";
}
void afis(int q,int p){
     int ind;
     ind=q;
     while (p!=0) {
           ind=v[ind];
           p--; //0 1 2 2 4 1 6 0 8 8 10 10 12
           }
     solutie = ind;
}

int main(){
citire();
for (i=1;i<=m; i++){
    f>>q>>p;
    afis(q,p);
    scriere(solutie);
}
}