/************************************************
* Au: Hany01
* Date: Aug 13th, 2018
* Prob: UOJ117 欧拉回路
* Email: hany01@foxmail.com
* Inst: Yali High School
************************************************/
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
#define rep(i, j) for (register int i = 0, i##_end_ = (j); i < i##_end_; ++ i)
#define For(i, j, k) for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++ i)
#define Fordown(i, j, k) for (register int i = (j), i##_end_ = (k); i >= i##_end_; -- i)
#define Set(a, b) memset(a, b, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define x first
#define y second
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define SZ(a) ((int)(a).size())
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define y1 wozenmezhemecaia
template <typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
inline int read() {
static int _, __; static char c_;
for (_ = 0, __ = 1, c_ = getchar(); c_ < '0' || c_ > '9'; c_ = getchar()) if (c_ == '-') __ = -1;
for ( ; c_ >= '0' && c_ <= '9'; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
return _ * __;
}
const int maxn = 1e5 + 5, maxm = 4e5 + 5;
int ty, e, beg[maxn], nex[maxm], v[maxm], in[maxn], out[maxn], stk[maxm >> 1], top, vis[maxm >> 1];
inline void add(int uu, int vv) { v[++ e] = vv, nex[e] = beg[uu], beg[uu] = e, ++ in[vv], ++ out[uu]; }
void DFS(int u) {
register int tmp;
for (register int& i = beg[u]; i; i = nex[i])
if (chkmax(vis[ty == 1 ? (i >> 1) : i], 1)) {
if (ty == 1) tmp = (i & 1) ? -(i >> 1) : (i >> 1);
else tmp = i;
DFS(v[i]), stk[++ top] = tmp;
}
}
int main()
{
#ifdef hany01
freopen("uoj117.in", "r", stdin);
freopen("uoj117.out", "w", stdout);
#endif
if ((ty = read()) == 1) e = 1;
static int n = read(), m = read(), uu, vv;
For(i, 1, m) {
uu = read(), vv = read(), add(uu, vv);
if (ty == 1) add(vv, uu);
}
if (ty == 1) { For(i, 1, n) if (out[i] & 1) return puts("NO"), 0; }
else { For(i, 1, n) if (in[i] ^ out[i]) return puts("NO"), 0; }
DFS(v[ty == 1 ? 2 : 1]);
if (top < m) puts("NO");
else {
puts("YES");
Fordown(i, top, 1) printf("%d ", stk[i]);
}
return 0;
}
【UOJ117】欧拉回路 模板
最新推荐文章于 2023-07-15 11:02:21 发布