Cod sursa(job #314801)

Utilizator pcinfoCarmen Popescu pcinfo Data 12 mai 2009 23:21:35
Problema Stramosi Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.34 kb
#include<fstream>

using namespace std;

ifstream f("stramosi.in");
ofstream g("stramosi.in");

int a[250010];

int main()
{
	int m,n,i,x,y;

	f>>n>>m;
	for (i=1;i<=n;i++)
		f>>a[i];
	for (i=0;i<m;i++)
	{
		f>>x>>y;
		while (y!=1&&a[x])
		{
			x=a[x];
			y--;
		}
		g<<a[x]<<"\n";
	}
	f.close();
	f.close();
	return 0;
}