Cod sursa(job #697529)

Utilizator hunter_ionutzzzFarcas Ionut hunter_ionutzzz Data 29 februarie 2012 09:40:32
Problema Pioni Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb
#include<fstream>
using namespace std;
ifstream fin("pioni.in");
ofstream fout("pioni.out");
typedef struct nod{nod *next;
				   int val;
};
int n,m,k,i,grad,aux;
nod *v[50001];
inline void recurs(int x,int pas)
{nod *q=v[x];
	if (q)
		while (q)
		{   recurs(q->val,pas+1);
			q = q->next;
		}
	else
		if (grad < pas)
			grad = pas;
}	
int main()
{int t,n,m,a,b,j,k,max1;
 nod *q;
    fin >> t >> n >> m;
	for (i=1;i<=m;++i)
	{   fin >> a >> b;
		q = new nod;
	    q-> next = v[a];
		q-> val = b;
	    v[a] = q;
	}
	for (j=1;j<=t;++j)
	{   fin >> k;
	    max1= 0;
	    for (i=1;i<=k;++i)
		{	grad = 0;
			fin >> aux;
			recurs(aux,0);
			if (grad > max1)
				max1 = grad;
		}
		if (max1 % 2 == 1)
		    fout << "Nargy" << '\n';
		else
			fout << "Fumeanu" << '\n';
	}
	return 0;
}