Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<iomanip>
- #include<vector>
- #include<algorithm>
- #include<tuple>
- #include<functional>
- #include<numeric>
- #include<random>
- #include<unordered_map>
- #include<set>
- #include<map>
- #include<unordered_set>
- #include<cassert>
- #include<cmath>
- #include<queue>
- #include<stack>
- #include<sstream>
- // #define endl '\n'
- using namespace std;
- using ll=long long;
- using ull=unsigned long long;
- using ld=long double;
- using sstream=stringstream;
- template<typename T1,typename T2=T1> using P=pair<T1,T2>;
- template<typename T> using V=vector<T>;
- template<typename T> using F=function<T>;
- void _debug() {cerr << '\n';}
- template <typename A, typename... B>
- void _debug(A a, B... b) {cerr << a << ' ', _debug(b...);}
- #define debug(...) cerr << '(' << (#__VA_ARGS__) << ") : ", _debug(__VA_ARGS__)
- template<typename T>
- ostream& operator<<(ostream& os,const V<T>& v){
- for(const auto& i:v)
- os<<i<<' ';
- return os;
- }
- template<typename T>
- ostream& operator<<(ostream& os,const unordered_set<T>& v){
- for(const auto& i:v)
- os<<i<<' ';
- return os;
- }
- template<typename T1,typename T2>
- ostream& operator<<(ostream& os,const P<T1,T2>& p){
- return os<<'('<<p.first<<','<<p.second<<") ";
- }
- mt19937 mt(hash<string>()(":poop:"));
- constexpr int inf=0x3f3f3f3f;
- constexpr ll infll=0x3f3f3f3f3f3f3f3f;
- constexpr int mod=1e9+7;
- inline void init(){
- }
- inline void solve() {
- int n,m;cin>>n>>m;
- V<V<P<ll,int>>> e(n);
- V<bool> vis(m,false);
- V<int> out(n,0);
- for(int i=0;i<m;i++){
- int a,b;cin>>a>>b;a--,b--;
- e[a].emplace_back(b,i);
- e[b].emplace_back(a,i);
- out[a]++,out[b]++;
- }
- if(!out[0]){
- cout<<"IMPOSSIBLE"<<endl;
- return;
- }
- for(auto i:out)
- if(i&1){
- cout<<"IMPOSSIBLE"<<endl;
- return;
- }
- // debug(out);
- V<int> ans{1};
- F<void(int,int,int)> dfs=[&](int u,int v,int i){
- if(vis[i]) return;
- vis[i]=true;
- for(auto [x,j]:e[v])
- if(!vis[j]) dfs(v,x,j);
- ans.emplace_back(u+1);
- };
- for(auto [v,i]:e[0])
- dfs(0,v,i);
- if((int)ans.size()!=m+1){
- cout<<"IMPOSSIBLE"<<endl;
- return;
- }
- for(auto i:ans)
- cout<<i<<' ';
- }
- signed main(){
- // cin.tie(nullptr)->sync_with_stdio(false);
- signed T=1;
- // cin>>T;
- init();
- while(T--)
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement