Cod sursa(job #2050749)

Utilizator pibogaBogdan piboga Data 28 octombrie 2017 11:13:56
Problema Sortare topologica Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.84 kb
#include <fstream>
#include <algorithm>
#include <vector>
#define mxvf 100002

using namespace std;

ifstream fin ("sortaret.in");
ofstream fout("sortaret.out");

bool viz[mxvf];
int i,z,nvf,nmc,crt,x,y;
int afis[mxvf],sol;

vector <int> tab[mxvf];

void dfs(int nod)
{
    viz[nod]=1;
    //afis[++z]=nod;
    fout<<nod<<' ';

    vector <int>::iterator it;

    for ( it=tab[nod].begin();it!=tab[nod].end();++it)
    {
        int need=*it;
        if (!viz[need])
            dfs(need);
    }


}

int main()
{
    fin >> nvf >> nmc  ;

    for (i=1;i<=nmc;++i)
    {
        fin >> x >> y;
        tab[x].push_back(y);
        tab[y].push_back(x);

    }

    crt=1;


    dfs(crt);
    sol=1;

    for (i=1;i<=nvf;++i)
    {
        if (!viz[i])
        {
            dfs(i);
        }
    }


}