Pagini recente » Cod sursa (job #2075506) | Cod sursa (job #1911001) | Cod sursa (job #2658390) | Cod sursa (job #33585) | Cod sursa (job #600688)
Cod sursa(job #600688)
#include <stdio.h>
#include <vector>
#define NMax 100010
using namespace std;
const char IN[]="mesaj4.in",OUT[]="mesaj4.out";
int N,M;
bool visit[NMax] , visit2[NMax];
vector<int> ad[NMax];
void bfs(int x=1)
{
visit[x]=true;
for ( typeof(ad[x].begin()) it=ad[x].begin();it<ad[x].end();++it)
if (!visit[*it])
{
bfs(*it);
printf("%d %d\n",*it,x);
}
}
void bfs2(int x=1)
{
visit2[x]=true;
for ( typeof(ad[x].begin()) it=ad[x].begin();it<ad[x].end();++it)
if (!visit2[*it])
{
printf("%d %d\n",x,*it);
bfs2(*it);
}
}
int main()
{
int x,y;
freopen(IN,"r",stdin);
scanf("%d%d",&N,&M);
while (M--)
{
scanf("%d%d",&x,&y);
ad[x].push_back(y);
ad[y].push_back(x);
}
fclose(stdin);
freopen(OUT,"w",stdout);
if (N==1){
printf("0\n");
fclose(stdout);
return 0;
}
printf("%d\n",2*N-2);
bfs();
bfs2();
fclose(stdout);
return 0;
}