Cod sursa(job #2765924)

Utilizator Edyci123Bicu Codrut Eduard Edyci123 Data 30 iulie 2021 13:19:38
Problema Sortare topologica Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.5 kb
#include <bits/stdc++.h>
#define NMAX 50005

using namespace std;

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

int n, m;
bitset <NMAX> v;
vector <int> edges[NMAX];

void dfs(int nod)
{
    v[nod] = 1;
    g << nod << " ";
    for(auto k : edges[nod])
        if(!v[k])
            dfs(k);
}

int main()
{
    f >> n >> m;

    for(int i = 1; i <= m; i++)
    {
        int x, y;
        f >> x >> y;
        edges[x].push_back(y);
    }

    dfs(1);

    return 0;
}