Pagini recente » Cod sursa (job #452878) | Cod sursa (job #1830526) | Cod sursa (job #2943702) | Cod sursa (job #1378999) | Cod sursa (job #1541316)
#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!