Cod sursa(job #2664689)

Utilizator MattiaMattia Iojica Mattia Data 29 octombrie 2020 10:04:08
Problema Sortare topologica Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.61 kb
#include <bits/stdc++.h>
#define NMAX 50005

using namespace std;

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

bitset <NMAX> v;

vector <int> l[NMAX];

void dfs(int nod)
{
    v[nod] = 1;

    g << nod << " ";

    for(int i = 0; i < l[nod].size(); i++)
        if(v[l[nod][i]] == 0)
        {
            //cout << l[nod][i] << '\n';
            dfs(l[nod][i]);
        }
}

int main()
{
    int n, m;

    f >> n >> m;

    for(int i = 1; i <= m; i++)
    {
        int x, y;
        f >> x >> y;

        l[x].push_back(y);
    }

        dfs(1);

    return 0;
}