Cod sursa(job #2023808)

Utilizator GabiTulbaGabi Tulba-Lecu GabiTulba Data 19 septembrie 2017 15:37:05
Problema Mesaj4 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <bits/stdc++.h>

#define MaxN 100005
#define INF 2140000000

using namespace std;

FILE *IN,*OUT;

int N,M,X,Y;
bool found[MaxN];
vector<int> Graph[MaxN];
void DFS(int node,int father)
{
    if(father)
        fprintf(OUT,"%d %d\n",father,node);
    found[node]=1;
    for(int i=0;i<Graph[node].size();i++)
        if(!found[Graph[node][i]])
            DFS(Graph[node][i],node);
    if(father)
        fprintf(OUT,"%d %d\n",node,father);
}
int main()
{
    IN=fopen("mesaj4.in","r");
    OUT=fopen("mesaj4.out","w");

    fscanf(IN,"%d%d",&N,&M);

    for(int i=1;i<=M;i++)
    {
        fscanf(IN,"%d%d",&X,&Y);
        Graph[X].push_back(Y);
        Graph[Y].push_back(X);
    }
    fprintf(OUT,"%d\n",2*N-2);
    DFS(1,0);
    return 0;
}