Pagini recente » Cod sursa (job #1042271) | Cod sursa (job #2004075) | Cod sursa (job #965238) | Cod sursa (job #1451840) | Cod sursa (job #1141091)
#include <cstdio>
#include <vector>
#include <queue>
#define nmax 100009
using namespace std;
struct vecini
{
vector<int> v;
};
vecini g[nmax];
int deg[nmax];
vector <int> a1;vector <int>a2;
int suma;
queue<int> q;
bool viz[nmax];
int main()
{
freopen("ciclueuler.in","r",stdin);
freopen("ciclueuler.out","w",stdout);
int i,j,n,m,x,y;
scanf("%d%d",&n,&m);
suma=2*m;
for(i=1;i<=n;i++)
{
scanf("%d%d",&x,&y);
g[x].v.push_back(y);deg[x]++;
if(x!=y)
{
g[y].v.push_back(x); deg[y]++;
}
}
q.push(1);
viz[1]=true;
while(q.empty()==0)
{
int top=q.front();
int lung=g[top].v.size();
for(i=0;i<lung;++i)
{
if(viz[g[top].v[i]]==false)
{
viz[g[top].v[i]]=true;
q.push(g[top].v[i]);
}
}
q.pop();
}
for(i=1;i<=n;i++)
{
if(viz[i]==false||deg[i]%2!=0)
{
printf("-1\n");
return 0;
}
}
/*while(suma!=0)
{
for(i=1;i<=n;i++)
if(deg[i]!=0)
{
DFS(i);
break;
}
lung=a2.size();
for(i=0;i<lung;++i)
{
if(deg[a2[i]]==0)
printf("%d",a2[i]);
else
for(j=i;j<=lung;j++)
{
a1.push_back(j);
}
}
}
return 0;*/
}