Pagini recente » Cod sursa (job #2990541) | Cod sursa (job #1577929) | Arhiva de probleme | Cod sursa (job #359262) | Cod sursa (job #2215196)
#include <bits/stdc++.h>
using namespace std;
ifstream f ("ciclueuler.in");
ofstream g ("ciclueuler.out");
vector <int> :: iterator it;
vector <int> G[100002];
list <int> Q;
const int bsize = (1 << 16);
char ch[bsize+1];
int n, m, x, y, nr, pos;
bool ok = true;
void read (int &x)
{
x = 0;
while (!isdigit(ch[pos]))
{
pos++;
if (pos == bsize)
{
pos = 0;
fread(ch,1,bsize,stdin);
}
}
while (isdigit(ch[pos]))
{
x = x * 10 + ch[pos] - '0';
pos++;
if (pos == bsize)
{
pos = 0;
fread(ch,1,bsize,stdin);
}
}
}
int main()
{
ios_base :: sync_with_stdio (false);
freopen("ciclueuler.in","r",stdin);
freopen("ciclueuler.ouy","r",stdout);
pos = 0;
fread(ch,1,bsize,stdin);
read(n);
read(m);
for (int i = 1; i <= m; i++)
{
read(x);
read(y);
G[x].push_back(y);
G[y].push_back(x);
}
for (int i = 1; i <= n; i++)
{
if (G[i].size() % 2 == 1)
{
ok = false;
break;
}
}
if (ok == false) cout << "-1";
else
{
Q.push_back(1);
while (!Q.empty())
{
x = Q.front();
if (G[x].size() == 0)
{
if (nr < m)
{
g << x << " ";
nr++;
}
Q.pop_front();
continue;
}
y = G[x].back();
Q.push_front(y);
G[x].pop_back();
for (it = G[y].begin(); it != G[y].end(); it++)
{
if (*it == x)
{
G[y].erase(it);
break;
}
}
}
}
return 0;
}