Cod sursa(job #2667865)

Utilizator florescu.mirunaMiruna Stefania Florescu florescu.miruna Data 3 noiembrie 2020 23:57:16
Problema Sortare topologica Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.55 kb
#include <iostream>
#include<fstream>
#include<vector>

using namespace std;

ifstream f ("sortaret.in");
ofstream g ("sortaret.out");

vector<int> a[10001];
bool viz[10001];
int n,m;
void citire()
{
    int x,y;

    f>>n>>m;

    while(m)
    {
        f>>x>>y;
        a[x].push_back(y);
        m--;
    }
}
void DFS(int x)
{
    g<<x<<" ";
    viz[x] = true;
    for(auto it: a[x])
        if(!viz[it])
            DFS(it);

}
int main()
{
    citire();

    DFS(1);

    f.close();
    g.close();
    return 0;
}