Cod sursa(job #2756640)
| Utilizator | Data | 2 iunie 2021 10:30:53 | |
|---|---|---|---|
| Problema | Sortare topologica | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <cstdio>
#include <vector>
using namespace std;
vector<vector<int>> Graph;
vector<bool> used;
void DFS(int k)
{
printf("%d ", k + 1);
used[k] = true;
for (auto it : Graph[k])
if (!used[it])
DFS(it);
}
int main()
{
freopen("sortaret.in", "r", stdin);
freopen("sortaret.out", "w", stdout);
int N, M;
scanf("%d%d", &N, &M);
Graph.resize(N);
used.resize(N);
for (int i = 0; i < M; ++i) {
int a, b;
scanf("%d%d", &a, &b);
--a;
--b;
Graph[a].emplace_back(b);
}
DFS(0);
return 0;
}
