Cod sursa(job #2662162)

Utilizator ArkhamKnightyMarcus ArkhamKnighty Data 23 octombrie 2020 16:51:45
Problema Ciclu Eulerian Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.07 kb
#include <fstream>
#include <vector>
#define MMAX 500005
#define NMAX 100005
using namespace std;

ifstream cin("ciclueuler.in");
ofstream cout("ciclueuler.out");

bool vec[MMAX];
bool viz[NMAX];
int grad[NMAX], n, m;
vector < vector < pair < int, int > > > G;

void citire()
{
    int x, y;
    cin >> n >> m;

    G.resize(n + 5);
    for(int i = 1 ; i <= m ; i++)
        cin >> x >> y,
        G[x].push_back( make_pair(y, i)),
        G[y].push_back( make_pair(x, i)),
        grad[x]++, grad[y]++;


}

void DFS(int nod)
{
    viz[nod] = 1;

    for(int i = 0 ; i < G[nod].size() ; i++)
        if(!viz[G[nod][i].first ])
            DFS(G[nod][i].first);
}

bool verif()
{
    bool ok = 1;
    for(int i = 1; i <= n; ++i)
        if(grad[i] % 2 == 1)
            ok = false;

    if(!ok)
        return false;

    for(int i = 1 ; i <= n ; i++)
        if(!viz[i])
            return false;

    return true;
}

int main()
{
    citire();
    DFS(1);
    if(verif())
    {

    }
    else
        cout << -1;
    return 0;
}