diff --git a/AcWing/1184/1184.cpp b/AcWing/1184/1184.cpp new file mode 100644 index 00000000..e1aef83b --- /dev/null +++ b/AcWing/1184/1184.cpp @@ -0,0 +1,94 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5, + M = 2e5 + 5; + +int t, n, m, cnt, ans[M]; +int idx, head[N], edge[M << 1], next[M << 1]; +int din[N], dout[N]; +bool vis[M << 1]; + +void add(int u, int v) { + next[idx] = head[u]; + edge[idx] = v; + head[u] = idx++; +} + +void dfs(int u) { + for (int &i = head[u]; ~i;) { + if (vis[i]) { + i = next[i]; + continue; + } + + int v = edge[i]; + + vis[i] = true; + if (t == 1) vis[i ^ 1] = true; + + int x; + if (t == 1) x = i & 1 ? -(i >> 1) - 1 : (i >> 1) + 1; + else x = i + 1; + + i = next[i]; + + dfs(v); + + ans[++cnt] = x; + } +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> t >> n >> m; + + memset(head, 0xff, sizeof(head)); + + for (int i = 1, u, v; i <= m; i++) { + cin >> u >> v; + + add(u, v); + if (t == 1) add(v, u); + + din[u]++, dout[v]++; + } + + for (int i = 1; i <= n; i++) { + if (t == 1 && (din[i] + dout[i] & 1) || t == 2 && (din[i] != dout[i])) { + cout << "NO" << endl; + + exit(0); + } + } + + for (int i = 1; i <= n; i++) { + if (~head[i]) { + dfs(i); + + break; + } + } + + if (cnt < m) { + cout << "NO" << endl; + + exit(0); + } + + cout << "YES" << endl; + + for (int i = cnt; i; i--) { + cout << ans[i] << ' '; + } + + cout << endl; + + return 0; +} diff --git a/AcWing/1184/data/19.in b/AcWing/1184/data/19.in new file mode 100644 index 00000000..c25df48b --- /dev/null +++ b/AcWing/1184/data/19.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:47657266b59b774b26470521cefc7e29908884cd7678e8006ade360ad7e5447b +size 26 diff --git a/AcWing/1184/data/19.out b/AcWing/1184/data/19.out new file mode 100644 index 00000000..0fece9f5 --- /dev/null +++ b/AcWing/1184/data/19.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bc46d85b74c69d458ab5e1f6bbb1f6ef24be48a4b9face9758e39b207e7c00a4 +size 20