Pagini recente » Cod sursa (job #1807192) | Cod sursa (job #2320321) | Cod sursa (job #2076461) | Cod sursa (job #2884493) | Cod sursa (job #3196751)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("mesaj4.in");
ofstream fout("mesaj4.out");
const int DIM = 100010;
int n, m, x, y;
vector<int> l[DIM];
vector<pair<int, int>> sol;
bool visited[DIM];
void dfs(int node) {
visited[node] = true;
for (auto adjNode : l[node]) {
if (!visited[adjNode]) {
dfs(adjNode);
sol.emplace_back(adjNode, node);
}
}
}
int main() {
fin >> n >> m;
for (int i = 1; i <= m; i++) {
fin >> x >> y;
l[x].emplace_back(y);
l[y].emplace_back(x);
}
dfs(1);
for (int node = 1; node <= n; node++) {
if (!visited[node]) {
fout << -1;
return 0;
}
}
fout << 2 * sol.size() << '\n';
for (auto elem = sol.begin(); elem != sol.end(); elem++)
fout << elem->first << ' ' << elem->second << '\n';
for (auto elem = sol.rbegin(); elem != sol.rend(); elem++)
fout << elem->second << ' ' << elem->first << '\n';
return 0;
}