Pagini recente » Cod sursa (job #2685213) | Cod sursa (job #2322192) | Cod sursa (job #1961757) | Cod sursa (job #2758005) | Cod sursa (job #2290514)
#include <fstream>
#include <vector>
#include <bitset>
#include <algorithm>
#define pb push_back
using namespace std;
ofstream g ("ciclueuler.out");
struct code {
int x , y;
};
int const NM = 1e5 , BUFF = 1e6;
char buff [BUFF];
int p;
string s;
vector <int> v2 [1 + NM];
vector <int> e;
bool viz [1 + 5 * NM];
code v [1 + 5 * NM];
void out (){
g << s;
}
void next (){
if (++ p == BUFF){
p = 0;
fread (buff , 1 , BUFF , stdin);
}
}
string mark (int a){
if (! a)
return " ";
return mark (a / 10) + (char)(a % 10 + '0');
}
void euler (int node){
for(auto i : v2 [node]){
if (! viz [i]){
int to = v [i] . x;
if (to == node)
to = v [i] . y;
viz [i] = true;
euler (to);
}
}
s += mark (node);
}
int nextc (){
while (! isdigit (buff [p]))
next ();
int a = 0;
while (isdigit (buff [p])){
a = a * 10 + buff [p] - '0';
next ();
}
return a;
}
void nu (){
g << -1;
return;
}
int n;
void flood (int node){
viz [node] = true;
for(auto i : v2 [node]){
int next = v [i] . x;
if (v [i] . x == node){
next = v [i] . y;
}
if (! viz [next])
flood (next);
}
}
bool check (){
for(int i = 1; i <= n ; ++ i)
if (v2 [i] . size () % 2)
return true;
int counts = 0;
for(int i = 1 ; i <= n ; ++ i)
if (! viz [i]){
flood (i);
++ counts;
}
if (counts > 1)
return true;
return false;
}
int main()
{
int m;
freopen ("ciclueuler.in" , "r" , stdin);
fread (buff , 1 , BUFF , stdin);
n = nextc ();
m = nextc ();
for(int i = 1 ; i <= m ; ++ i){
int a , b;
a = nextc ();
b = nextc ();
v2 [a] . pb (i);
v2 [b] . pb (i);
v [i] = {a , b};
}
if (check ()){
nu ();
return 0;
}
/// parsare la afisare cred
fill (viz + 1 , viz + m + 1 , false);
for(int i = 1 ; i <= m ; ++ i)
if (! viz [i]){
euler (i);
out ();
return 0;
}
return 0;
}