Pagini recente » Cod sursa (job #1472217) | Cod sursa (job #305117) | Cod sursa (job #2190570) | Cod sursa (job #190815) | Cod sursa (job #2651521)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin ("sortaret.in");
ofstream fout ("sortaret.out");
int main() {
int n, m;
fin >> n >> m;
vector<int> nodesSorted;
bool reached[n + 1] = {0};
int x, y;
for (int i = 0; i < n; i++) {
fin >> x >> y;
if (!reached[x])
nodesSorted.push_back(x);
if (!reached[y])
nodesSorted.push_back(y);
reached[x] = true;
reached[y] = true;
}
for (vector<int>::iterator it = nodesSorted.begin(); it != nodesSorted.end(); it++)
fout << *it << " ";
for (int i = 1; i <= n; i++)
if (!reached[i])
fout << i << " ";
return 0;
}