Pagini recente » Cod sursa (job #2298588) | Cod sursa (job #2075817) | Cod sursa (job #277944) | Cod sursa (job #2060937) | Cod sursa (job #1640747)
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
ifstream fin("mesaj4.in");
ofstream fout("mesaj4.out");
int N, M, solution;
pair<int, int> S[100010];
vector<int>L[100010];
bitset<100010>v;
void DFS(int node)
{
v[node] = 1;
for(int i = 0; i < L[node].size(); i ++)
{
if(v[ L[node][i] ] == 0)
{
DFS( L[node][i] );
solution ++;
S[solution].x = node;
S[solution].y = L[node][i];
}
}
}
int main()
{
fin >> N >> M;
for(int i = 1; i <= M; i ++)
{
int a, b;
fin >> a >> b;
L[a].push_back(b);
L[b].push_back(a);
}
DFS(1);
if(solution != N - 1)
{
fout << -1;
return 0;
}
fout << 2 * solution << '\n';
for(int i = 1; i <= solution; i ++)
{
fout << S[i].y << " " << S[i].x << '\n';
}
for(int i = solution; i >= 1; i --)
{
fout << S[i].x << " " << S[i].y << '\n';
}
return 0;
}