Cod sursa(job #1628197)
Utilizator | Data | 3 martie 2016 21:50:15 | |
---|---|---|---|
Problema | Sortare topologica | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.55 kb |
#include <fstream>
#include <vector>
using namespace std;
ifstream f("sortaret.in");
ofstream g("sortaret.out");
const int nmax = 50005;
int n,m,x,y,i;
vector <int> v[nmax];
bool viz[nmax];
void DF(int x)
{
viz[x] = 1;
for (auto it:v[x])
if (!viz[it])
DF(it);
g<<x<<" ";
}
int main()
{
f>>n>>m;
for (i=1;i<=m;i++)
{
f>>x>>y;
//v[x].push_back(y);
v[y].push_back(x);
}
for (i=1;i<=n;i++)
if (!viz[i])
DF(i);
return 0;
}