Cod sursa(job #2952647)
| Utilizator | Data | 9 decembrie 2022 17:47:48 | |
|---|---|---|---|
| Problema | Sortare topologica | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.47 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
int n, m, x, y;
vector<int> a[50001];
void sorttop(int i) {
sort(a[i].begin(), a[i].end());
for (int x : a[i]) {
fout << x << " ";
}
for (int x : a[i]) {
sorttop(x);
}
}
int main() {
fin >> n >> m;
for (int i = 0; i < m; i++) {
fin >> x >> y;
a[x].push_back(y);
}
fout << "1 ";
sorttop(1);
}
