Cod sursa(job #2890876)
| Utilizator | Data | 16 aprilie 2022 20:54:36 | |
|---|---|---|---|
| Problema | Sortare topologica | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
int n, m;
vector <int> graph[50005];
void DFS(int node)
{
fout << node << ' ';
for (int currNode : graph[node])
{
DFS(currNode);
}
}
int main()
{
fin >> n >> m;
for (int i = 0; i < m; i++)
{
int a, b;
fin >> a >> b;
graph[a].push_back(b);
}
DFS(1);
fout << '\n';
}