Cod sursa(job #1541316)

Utilizator iordache.bogdanIordache Ioan-Bogdan iordache.bogdan Data 3 decembrie 2015 22:13:23
Problema Pioni Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.25 kb
#include <fstream>
#include <algorithm>
#include <cstring>
#include <vector>

using namespace std;

vector<int> *graph, win;
vector<bool> vis;

void dfs(int node) {

	vis[node] = true;

	for (vector<int>::iterator adj = graph[node].begin(); adj != graph[node].end(); ++adj) {

		if (vis[*adj] == false)
			dfs(*adj);

		if (!win[*adj]) {

			win[node] = *adj;

		}

	}

}

int main() {

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

	int t, n, m;
	fin >> t >> n >> m;

	graph = new vector<int>[n + 1];
	for (int i = 1; i <= m; ++i) {

		int x, y;
		fin >> x >> y;

		graph[x].push_back(y);

	}

	vis.resize(n + 1, false);
	win.resize(n + 1, 0);
	for (int i = 1; i <= n; ++i) {

		if (vis[i])
			continue;

		dfs(i);

	}

	while (t--) {

		int k;
		fin >> k;

		vector<int> sol;

		for (int i = 1; i <= k; ++i) {

			int x;
			fin >> x;

			if (win[x])
				sol.push_back(x);

		}

		if (sol.size() == 0)
			fout << "Fumeanu\n";
		else {

			fout << "Nargy\n" << sol.size() << ' ';

			for (vector<int>::iterator curr = sol.begin(); curr != sol.end(); ++curr)
				fout << *curr << ' ' << win[*curr] << ' ';

			fout << '\n';

		}

	}

	return 0;

}

//Trust me, I'm the Doctor!