Cod sursa(job #15059)

Utilizator sigridMaria Stanciu sigrid Data 10 februarie 2007 16:57:06
Problema Stramosi Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.42 kb
#include<fstream.h>
unsigned long v[2500],s,c;
unsigned long strm(unsigned long x,unsigned long n,unsigned long c)
{if(c<=n)
  {s=v[x];
   x=s;
   strm(x,n,c+1);
  }
 else return s;
}
int main()
{int i,n,m,x;
 ifstream f("stramosi.in");
 ofstream g("stramosi.out");
 f>>n>>m;
 for(i=1;i<=n;i++) f>>v[i];
 for(i=1;i<=m;i++)
  {f>>x>>n;
   g<<strm(x,n,1)<<'\n';
  }
 f.close();
 g.close();
return 0;
}