Mai intai trebuie sa te autentifici.
Cod sursa(job #1374053)
| Utilizator | Data | 4 martie 2015 22:25:40 | |
|---|---|---|---|
| Problema | Sortare topologica | Scor | 70 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.78 kb |
#include <fstream>
#include <vector>
#define nmax 50001
using namespace std;
ifstream is ("sortaret.in");
ofstream os ("sortaret.out");
vector <int> V[nmax], ANSW;
int N, M, x, y, VIS[nmax];
void DFS(int);
int main()
{
is >> N >> M;
for(int i = 1; i <= M; ++i)
{
is >> x >> y;
V[x].push_back(y);
}
for(int i = 1; i < N; ++i)
if(!VIS[i]) DFS(i);
vector<int>::iterator it;
for(it = ANSW.end()-1; it >= ANSW.begin(); --it)
os << *it << " ";
is.close();
os.close();
return 0;
}
void DFS(int node)
{
VIS[node] = true;
vector<int>::iterator it;
for(it = V[node].begin(); it != V[node].end(); ++it)
if(!VIS[*it])
DFS(*it);
ANSW.push_back(node);
}
