Cod sursa(job #607742)

Utilizator blustudioPaul Herman blustudio Data 13 august 2011 13:49:03
Problema Sortare topologica Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.81 kb
#include <fstream>
#include <vector>
using namespace std;

struct Node
{
	vector<unsigned long int> m_Vertices;
	bool m_Visited;
};

Node Graph[50000];
unsigned long int n, m, x, y, b;
vector<unsigned long int> Print;

void visit(unsigned long int t)
{
	Graph[t].m_Visited = true;
	Print.push_back(t);
	for (unsigned long int i=0; i<Graph[t].m_Vertices.size(); i++)
	{
		visit(Graph[t].m_Vertices[i]);
	}
}

int main()
{
	ifstream fin("sortaret.in");
	ofstream fout("sortaret.out");
	fin >> n >> m;
	fin >> x >> y;
	Graph[x].m_Vertices.push_back(y);
	b = x;
	for (unsigned long int i=1; i<m; i++)
	{
		fin >> x >> y;
		Graph[x].m_Vertices.push_back(y);
	}
	visit(b);
	for(unsigned long int i=0; i<Print.size(); i++)
		fout << Print[i] << " ";
	fin.close();
	fout.close();
	return 0;
}