Cod sursa(job #804455)

Utilizator DaNutZ2UuUUBB Bora Dan DaNutZ2UuU Data 29 octombrie 2012 20:34:35
Problema Sortare topologica Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.64 kb
#include <fstream>
#include <vector>

using namespace std;

//ifstream fin("input.txt");
//ofstream fout("output.txt");

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

int n, m;
int pus[50001];
vector <int> V[50001];

void citire()
{
    int x, y;

    fin >> n >> m;
    while(fin >> x >> y)
    {
        V[x].push_back(y);
        V[y].push_back(x);
    }
}

void DF(int k)
{
    pus[k] = 1;

    fout << k << " ";
    for(int i = 0; i < V[k].size(); i++)
        if(!pus[V[k][i]]) DF(V[k][i]);
}

int main()
{
    citire();
    DF(1);

    fin.close();
    fout.close();
    fin.close();
}