Cod sursa(job #948329)

Utilizator tibi9876Marin Tiberiu tibi9876 Data 9 mai 2013 22:35:38
Problema Ciclu Eulerian Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.17 kb
#include<fstream>
#include<vector>
#include<stack>
using namespace std;
 
vector <int> a[100001];
struct muchie 
{
    int x,y;
    bool z;
};
muchie v[500001];
int i,n,x,y,m;
stack <int> s;
 
ifstream f("ciclueuler.in");
ofstream g("ciclueuler.out");
 
void df(int x)
{
  
}       
 
void df2(int x)
{
    while (++a[x][0]<a[x].size())
    {
        int k=a[x][a[x][0]];
        if (v[k].z==0)
        {
            v[k].z=1;
            df(v[k].x+v[k].y-x);
        }
    }
}       
     
int main()
{
    f >> n >> m;
    for (i=1;i<=n;i++)
        a[i].push_back(0);
    for (i=1;i<=m;i++)
    {
        f >> x >> y;
        v[i].x=x;v[i].y=y;
        a[x].push_back(i);
        a[y].push_back(i);
    }
    for (i=1;i<=n;i++)
        if (a[i].size()%2==0)
        {
            g << -1;
            return 0;
        }
	s.push(1);
	while (!s.empty())
	{
		x=s.top();
		while (++a[x][0]<a[x].size())
		{
			int k=a[x][a[x][0]];
			if (v[k].z==0)
			{
				v[k].z=1;
				s.push(v[k].x+v[k].y-x);
				break;
			}
		}
		if (a[x][0]>=a[x].size())
		{
			if (s.size()!=1)
				g << x << ' ';
			s.pop();
		}
	}
    return 0;
}