Cod sursa(job #2671337)
| Utilizator | Data | 11 noiembrie 2020 22:21:39 | |
|---|---|---|---|
| Problema | Sortare topologica | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.57 kb |
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
#define NMAX 50001
ifstream f("sortaret.in");
ofstream g("sortaret.out");
bool viz[NMAX];
int v;
vector<int> graf[NMAX];
void DFS(int x)
{
if (viz[x])
return;
viz[x] = 1;
for (auto i : graf[x])
{
g << i << " ";
DFS(i);
}
}
int main()
{
int m, x, y, i;
f >> v >> m;
for (i = 0; i < m; i++)
{
f >> x >> y;
graf[x].push_back(y);
}
g << 1 << " ";
DFS(1);
return 0;
}
