// compile: make data
// run: ./data < data.in
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#ifdef LOCAL
#include <debug/codeforces.h>
#define debug(x...) _debug_print(#x, x);
#define Debug(x...) _debug_print_format(#x, x);
#else
#define debug(x...)
#define Debug(x...)
#endif
template<typename...Args> void print_(Args...args){((cout<<args<<" "),...)<<endl;}
#define VI vector<int>
#define VII vector<vector<int>>
#define VIII vector<vector<vector<int>>>
#define rep(i,a,b) for(int i=(a);i<(int)(b);++i)
#define sz(v) ((int)(v).size())
#define print(...) print_(__VA_ARGS__);
#define FIND(a, x) ((find(a.begin(),a.end(),(x))!=a.end())?1:0)
#define cmin(x,...) x=min({(x), __VA_ARGS__})
#define cmax(x,...) x=max({(x), __VA_ARGS__})
#define INTMAX (int)(9223372036854775807)
#define INF (int)(1152921504606846976)
#define double long double
#define int long long
#define MAXN 200010
struct graph {
struct node {
int u, v, w;
int idx;
bool operator<(const node &other) const {return w < other.w; }
bool operator==(const node &other) const {return v == other.v && w == other.w; }
};
vector<vector<node>> e;
vector<vector<int>> invid;
node &inv(node &edge) {return e[edge.v][invid[edge.u][edge.idx]]; }
int n;
bool directed;
graph(int V, bool D = 0) {
n = V;
e.resize(n), invid.resize(n);
directed = D;
}
void add_edge(int u, int v, int w = 1, int wb = 1) {
e[u].push_back(node{u, v, w, sz(e[u])});
if (!directed) {
e[v].push_back(node{v, u, wb, sz(e[v])});
invid[u].push_back(sz(e[v]) - 1);
invid[v].push_back(sz(e[u]) - 1);
}
}
int eulerian_circuit(int s, vector<int> &route, int circuit = 1) {
vector<int> din(n, 0), dout(n, 0);
int E = 0;
rep(u, 0, n) for (auto &edge: e[u]) {
if (directed) ++din[edge.v], ++dout[u];
else din[edge.v] += edge.v > u, dout[u] += edge.v > u;
E += directed ? 1 : edge.v > u;
}
int error = 0;
rep(i, 0, n) error += directed ? abs(din[i] - dout[i]) : (din[i] + dout[i]) & 1;
if ((circuit && error) || (!circuit && error > 2)) return 0;
vector<vector<int>> vis(n);
rep(i, 0, n) vis[i].assign(sz(e[i]), 0);
vector<int> cur(n, 0);
function<void(int)> dfs = [&](int u) {
for (; cur[u] < sz(e[u]); ++cur[u]) {
int i = cur[u];
int v = e[u][i].v;
if (vis[u][i]) continue;
vis[u][i] = 1;
if (!directed) vis[v][inv(e[u][i]).idx] = 1;
dfs(v);
}
route.push_back(u);
};
dfs(s);
if (sz(route) != E+1) return 0;
reverse(route.begin(), route.end());
return 1;
}
void graphviz_dump(string filename = "graph.dot") {
ofstream gf; gf.open(filename);
gf << (directed ? "digraph" : "graph") << " {\n";
gf << " "; rep(i, 0, n) gf << i << " ;"[i==n-1]; gf << endl;
string notation = directed ? " -> " : " -- ";
bool weighted = 0;
for (auto es: e) for (auto edge: es) if (edge.w != 1) weighted = 1;
rep(u, 0, n) {
for (auto edge: e[u]) {
int v = edge.v, w = edge.w;
if (!directed && u > v) continue;
gf << " " << u << notation << v << (weighted ? " ;\n" : ";\n");
}
}
gf << "}\n";
}
};
int32_t main() {
ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int n, m; cin >> n >> m;
graph g(n, 1);
rep(i, 0, m) {
int u, v; cin >> u >> v; --u, --v;
g.add_edge(u, v);
}
vector<int> route;
g.graphviz_dump();
int valid = g.eulerian_circuit(0, route, 0);
if (route.empty() || route.back() != n-1) valid = 0;
if (!valid) cout << "IMPOSSIBLE" << endl;
else {
for (auto x: route) cout << x+1 << " ";
cout << endl;
}
return 0;
}
I recently switched over and the difference is night and day compared to other places I have visited. The games run flawlessly and the welcome rewards gave me the perfect start. It is rare to find a community that values fun and responsible play so much. casinl
I was skeptical at first but the registration process was completely hassle free. Withdrawals hit my account within the promised timeframe and the game fairness indicators give me confidence. It is a solid choice for anyone looking for consistent results. phtmt15
Been chasing sports bonuses across the continent and this platform really stands out for South American fans. The live betting interface is smooth and customer support actually responds fast. My weekend football parlay payouts arrived without a single delay. inkabetapuestas.cl