Pagini recente » Cod sursa (job #558883) | Cod sursa (job #1286770) | Cod sursa (job #298414) | Cod sursa (job #424920) | Cod sursa (job #2763531)
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <iostream>
using namespace std;
ifstream fin("sortaret.in");
ofstream fout("sortaret.out");
vector<int> v[50010];
bitset<100010> viz;
queue<int> q;
int n, m, nod_start;
void bfs(int nod_start) {
fout << nod_start << " ";
for (auto it:v[nod_start])
if (!viz[it]) {
bfs(it);
}
}
int main() {
fin >> n >> m;
int a, b;
fin >> a >> b;
nod_start = a;
v[a].push_back(b);
while (fin >> a >> b)
v[a].push_back(b);
bfs(nod_start);
return 0;
}