Cod sursa(job #1486939)

Utilizator robert.ologuOlogu Robert-Leonard robert.ologu Data 15 septembrie 2015 19:09:18
Problema Stramosi Scor 60
Compilator c Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <stdio.h>

#define FILE_IN  "stramosi.in"
#define FILE_OUT "stramosi.out"

#define MAX_MEMBERS 	250000
#define MAX_QUESTIONS 	300000


int main(int argc, char **argv)
{
	int i, j;
	int P, Q, S;
	int numMembers, numQuestions;
	int parent[MAX_MEMBERS+1];
	int questions[MAX_QUESTIONS];
	
	FILE* fIn  = fopen(FILE_IN, "r");
	FILE* fOut = fopen(FILE_OUT, "w");
	
	fscanf(fIn, "%d %d", &numMembers, &numQuestions);
	
	for( i=1; i<numMembers+1; ++i)
		fscanf( fIn, "%d", parent+i);
	
	for( i=0; i<numQuestions; ++i)
	{
		fscanf( fIn, "%d %d", &Q, &P);
		for(j=0; j<P; ++j)
			Q = parent[Q];
			
		fprintf(fOut, "%d\n", Q);
	}
	
	fclose(fIn);
	fclose(fOut);
	
	return 0;
}