|
| 1 | +/** |
| 2 | + * @file 15315.cpp |
| 3 | + * @author Macesuted (i@macesuted.moe) |
| 4 | + * @date 2025-12-09 |
| 5 | + * |
| 6 | + * @copyright Copyright (c) 2025 |
| 7 | + * |
| 8 | + */ |
| 9 | + |
| 10 | +#include <bits/stdc++.h> |
| 11 | +using namespace std; |
| 12 | + |
| 13 | +#define endl '\n' |
| 14 | + |
| 15 | +#define maxn 200005 |
| 16 | + |
| 17 | +vector<vector<int>> graph; |
| 18 | +int a[maxn], dep[maxn], fa[maxn]; |
| 19 | +bool vis[maxn]; |
| 20 | + |
| 21 | +vector<int> ans; |
| 22 | +int sum; |
| 23 | +void dfs(int p) { |
| 24 | + ans.push_back(p), a[p] ^= 1; |
| 25 | + vis[p] = true; |
| 26 | + for (auto q : graph[p]) { |
| 27 | + if (vis[q]) { |
| 28 | + if (sum && dep[q] <= dep[p] && !((dep[p] - dep[q]) & 1)) { |
| 29 | + sum = 0; |
| 30 | + int x = p; |
| 31 | + while (x != q) ans.push_back(x = fa[x]), a[x] ^= 1; |
| 32 | + ans.push_back(p), a[p] ^= 1; |
| 33 | + } |
| 34 | + continue; |
| 35 | + } |
| 36 | + dep[q] = dep[p] + 1, fa[q] = p, dfs(q); |
| 37 | + ans.push_back(p), a[p] ^= 1; |
| 38 | + if (a[q]) { |
| 39 | + ans.push_back(q), a[q] ^= 1; |
| 40 | + ans.push_back(p), a[p] ^= 1; |
| 41 | + } |
| 42 | + } |
| 43 | + return; |
| 44 | +} |
| 45 | + |
| 46 | +void solve(void) { |
| 47 | + int n, m, r; |
| 48 | + cin >> n >> m >> r; |
| 49 | + |
| 50 | + for (int i = 1; i <= n; i++) cin >> a[i], a[i] &= 1; |
| 51 | + |
| 52 | + graph.clear(), graph.resize(n + 1); |
| 53 | + for (int i = 1, x, y; i <= m; i++) cin >> x >> y, graph[x].push_back(y), graph[y].push_back(x); |
| 54 | + |
| 55 | + ans.clear(), sum = 0; |
| 56 | + for (int i = 1; i <= n; i++) sum ^= a[i], vis[i] = false; |
| 57 | + a[r] ^= 1, dep[r] = 0, dfs(r); |
| 58 | + |
| 59 | + for (int i = 1; i <= n; i++) |
| 60 | + if (a[i]) return cout << "No" << endl, void(); |
| 61 | + |
| 62 | + ans.pop_back(); |
| 63 | + reverse(ans.begin(), ans.end()); |
| 64 | + |
| 65 | + cout << "Yes" << endl << ans.size() << endl; |
| 66 | + for (auto x : ans) cout << x << ' '; |
| 67 | + cout << endl; |
| 68 | + |
| 69 | + return; |
| 70 | +} |
| 71 | + |
| 72 | +int main() { |
| 73 | + ios::sync_with_stdio(false), cin.tie(nullptr); |
| 74 | + |
| 75 | + int _ = 1; |
| 76 | + cin >> _; |
| 77 | + while (_--) solve(); |
| 78 | + |
| 79 | + return 0; |
| 80 | +} |
0 commit comments