Cod sursa(job #3032472)
Utilizator | Andrei Voicu 55andreiv55 | Data | 22 martie 2023 10:37:51 |
---|---|---|---|
Problema | Sortare topologica | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <fstream>
#include <set>
using namespace std;
const int N = 1e4 * 5 + 1;
ifstream in("sortaret.in");
ofstream out("sortaret.out");
bool fq[N];
set <int> mat[N];
int n;
void dfs(int x)
{
fq[x] = true;
out << x << " ";
for (auto k : mat[x])
dfs(k);
}
int main()
{
int n, m;
in >> n >> m;
for (int i = 0; i < m; i++)
{
int ns, nd;
in >> ns >> nd;
mat[ns].insert(nd);
}
dfs(1);
return 0;
}