Cod sursa(job #1341471)

Utilizator Darius15Darius Pop Darius15 Data 12 februarie 2015 19:31:37
Problema Ciclu Eulerian Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.77 kb
#include <fstream>
#include <bitset>
#include <vector>
#include <queue>
using namespace std;
ifstream f("ciclueuler.in");
ofstream g("ciclueuler.out");
int n,m,i,j,x,y;
bool ok;
bitset <100001> viz;
vector <int> v[100001];
queue <int> q;
int main()
{
    f>>n>>m;
    for (i=1;i<=m;i++)
    {
        f>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    q.push(1);
    while(!q.empty())
    {
        x=q.front();
        q.pop();
        viz[x]=true;
        for (j=0;j<v[x].size();j++)
        if (viz[v[x][j]]==false)
         q.push(v[x][j]);
    }
    ok=true;
    for (j=1;j<=n;j++)
        if ((viz[j]==false) || (v[j].size()%2==1))
                ok=false;
    if (ok==false)
    g<<-1;
    else g<<0<<'\n';
    return 0;
}