Pagini recente » Cod sursa (job #1909390) | Cod sursa (job #630119) | Cod sursa (job #2593429) | Cod sursa (job #1695775) | Cod sursa (job #2256343)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin ("mesaj4.in");
ofstream fout ("mesaj4.out");
const int NMax = 100000;
int N, M, k;
vector <int> G[NMax + 5];
bool Use[NMax + 5];
struct
{
int x, y;
}Sol[NMax + 5];
void Read()
{
fin>>N>>M;
for (int i = 1; i<=M; i++)
{
int x, y;
fin>>x>>y;
G[x].push_back(y);
G[y].push_back(x);
}
}
void DFS(int Nod)
{
Use[Nod] = 1;
for (int i = 0; i<(int)G[Nod].size(); i++)
{
int Vecin = G[Nod][i];
if (Use[Vecin] == 0)
{
DFS(Vecin);
Sol[++k].x = Vecin;
Sol[k].y = Nod;
}
}
}
int main()
{
Read();
DFS(1);
for (int i=1; i<=N; i++)
if (Use[i] == 0)
{
fout<<"-1";
break;
}
int Timp = 2*k;
fout<<Timp<<"\n";
for (int i=1; i<=k; i++)
fout<<Sol[i].x<<" "<<Sol[i].y<<"\n";
for (int i = k; i>=1; i--)
fout<<Sol[i].y<<" "<<Sol[i].x<<"\n";
return 0;
}