Cod sursa(job #937071)

Utilizator ericptsStavarache Petru Eric ericpts Data 9 aprilie 2013 15:09:25
Problema Pioni Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.16 kb
#include <fstream>
#include <vector>

#define pb push_back
#define forEach(G) for(typeof(G.begin()) it = G.begin() ; it != G.end() ; ++ it)

using namespace std;

const int maxn = 20100;

ifstream in("pioni.in");
ofstream out("pioni.out");

vector<int> G[maxn];
vector<int> show;
int n,m;
int head[maxn];
bool win[maxn];
bool viz[maxn];


void dfs(const int &node){
    viz[node] = 1;
    forEach(G[node]){
        if(!viz[*it])
            dfs(*it);

        if(!win[*it]){
            win[node] = 1;
            head[node] = *it;
        }
    }
}

void pre(){
    for(int i = 1 ; i <= n ; ++ i)
        if(!viz[i])
            dfs(i);
}


void solve(){
    int K,x;
    show.clear();
    in >> K;
    while(K--){
        in >> x;
        if(win[x])
            show.pb(x);
    }
    if(show.size()){
        out << "Nargy\n";
        out << show.size() << " ";
        forEach(show){
            out << *it << " " << head[*it] << " ";
        }out << "\n";
    }else{
        out << "Fumeanu\n";
    }
}

int main(){
    int T,a,b;
    in >> T >> n >> m;
    while(m--){
        in >> a >> b;
        G[a].pb(b);
    }
    pre();
    while(T--)
        solve();
    return 0;
}