Pagini recente » Cod sursa (job #2372680) | Cod sursa (job #877322) | Cod sursa (job #820672) | Cod sursa (job #728544) | Cod sursa (job #607742)
Cod sursa(job #607742)
#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;
}