Pagini recente » Cod sursa (job #1305487) | Cod sursa (job #1997314) | Cod sursa (job #1638566) | Cod sursa (job #427821) | Cod sursa (job #2011710)
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define oo 1000000000
#define PII pair <int, int>
using namespace std;
int n, m;
vector < int > V[100100];
bool v[100100];
vector < PII > R;
void dfs(int x){
v[x] = 1;
for (auto it : V[x])
if (!v[it]) R.pb({x, it}), dfs(it);
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
ifstream cin("mesaj4.in");
ofstream cout("mesaj4.out");
cin >> n >> m;
for (int i = 1, x, y; i <= m; i++) cin >> x >> y, V[x].pb(y), V[y].pb(x);
dfs(1);
int l = R.size();
if (l != n - 1) return cout << -1, 0;
cout << 2 * l << "\n";
for (auto it : R) cout << it.x << " " << it.y << "\n";
reverse(R.begin(), R.end());
for (auto it : R) cout << it.y << " " << it.x << "\n";
}