Pagini recente » Cod sursa (job #1774735) | Cod sursa (job #2388061) | Cod sursa (job #2388004) | Cod sursa (job #1780377) | Cod sursa (job #3331352)
// Copilot Rules:
// RULE: There shouldnt be any spaces in the code, except after commas.
// RULE: All variables in main should be declared globally, and can be used before they are defined.
// RULE: All open curly braces should be placed on the same line as the function or control structure they belong to, not on the line after.
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciclueuler.in"); //strudel
ofstream fout("ciclueuler.out"); //ciclueuler
struct aaa{
int nod,id;
};
int n,m,i,x,y,ok;
vector<aaa> v[100010];
stack<int> s;
stack<int> c;
int viz[500010];
int main()
{
fin>>n>>m;
for(i=1;i<=m;i++){
fin>>x>>y;
v[x].push_back({y,i});
v[y].push_back({x,i});
}
for(i=1;i<=n;i++){
if(v[i].size()%2){
fout<<"-1";
return 0;
}
}
s.push(1);
while(!s.empty()){
int nod=s.top();
ok=1;
for(auto it:v[nod]){
if(viz[it.id]==0){
viz[it.id]=1;
s.push(it.nod);
ok=0;
break;
}
}
if(ok==1){
c.push(nod);
s.pop();
}
}
while(!c.empty()){
x=c.top();
c.pop();
if(!c.empty())
fout<<x<<" ";
}
return 0;
}