Pagini recente » Cod sursa (job #902345) | Cod sursa (job #964674) | Cod sursa (job #2243183) | Cod sursa (job #2096970) | Cod sursa (job #2437495)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
struct lista
{
int value;
lista* next;
};
lista* head = NULL;
bool viz[50001];
void addNode(lista* &head, int val)
{
lista *p = new lista;
p->value = val;
p->next = head;
head = p;
}
void afis()
{
while (head != NULL)
{
fout << head->value << " ";
head = head->next;
}
}
int n, m;
vector <int> G[50001];
void dfs(int nod)
{
viz[nod] = true;
for (unsigned int i = 0; i < G[nod].size(); i++)
{
int vecin = G[nod][i];
if (viz[vecin])
continue;
dfs(vecin);
}
addNode(head, nod);
}
int main()
{
fin >> n >> m;
while (m--)
{
int x, y;
fin >> x >> y;
G[x].push_back(y);
}
dfs(1);
afis();
return 0;
}