Cod sursa(job #1373015)

Utilizator matei_cChristescu Matei matei_c Data 4 martie 2015 16:20:55
Problema Pioni Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.76 kb
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstring>
#include<set>
#include<map>
#include<cmath>
using namespace std ;

#define maxn 20005

int T, N, M, mut[maxn] ;

vector<int> graf[maxn] ;

vector< pair<int, int> > rez ;

bool sel[maxn], castig[maxn] ;

void dfs(int nod)
{
    sel[nod] = true ;

    for(size_t i = 0; i < graf[nod].size(); ++i)
    {
        int vecin = graf[nod][i] ;

        if( sel[vecin] == false )
            dfs(vecin) ;

        if( castig[vecin] == false )
        {
            castig[nod] = true ;
            mut[nod] = vecin ;
        }
    }
}

int main()
{
	std::ios_base::sync_with_stdio(false) ;

	freopen("pioni.in", "r", stdin);
	//freopen("pioni.out", "w", stdout);

    cin >> T >> N >> M ;

    for(int i = 1; i <= M; ++i)
    {
        int x, y ;
        cin >> x >> y ;

        graf[x].push_back(y) ;
    }

    for(int i = 1; i <= N; ++i)
        if( sel[i] == false )
            dfs(i) ;

    while( T-- )
    {
        rez.clear() ;

        int K ;
        cin >> K ;

        bool frumeanu = true ;

        for(int i = 1; i <= K; ++i)
        {
            int x;
            cin >> x ;

            if( castig[x] == true )
            {
                frumeanu = false ;
                rez.push_back( make_pair( x, mut[x] ) ) ;
            }
        }

        if( frumeanu == true )
            cout << "Frumeanu\n" ;
        else
        {
            cout << "Nargy\n" ;

            cout << rez.size() << " " ;

            for(size_t i = 0; i < rez.size(); ++i)
                cout << rez[i].first << " " << rez[i].second << " " ;

            cout << "\n" ;
        }
    }

	return 0 ;
}