1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| #include <cstdio> #include <utility> #include <vector>
inline int rd() { int x = 0, f = 1, c = getchar(); while (((c - '0') | ('9' - c)) < 0) f = c != '-', c = getchar(); while (((c - '0') | ('9' - c)) > 0) x = x * 10 + c - '0', c = getchar(); return f ? x : -x; }
using i64 = long long;
using pii = std::pair<int, int>; const int N = 3e5;
int n, m; i64 x, a[N + 5];
int fa[N + 5]; int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
std::vector<pii> g[N + 5]; int ans[N + 5], hd, tl; void dfs(int u, int fa) { for (auto [v, id] : g[u]) { if (v == fa) continue; dfs(v, u); if (a[u] + a[v] >= x) { a[u] = a[u] + a[v] - x; ans[hd++] = id; } else ans[tl--] = id; } }
int main() { n = rd(), m = rd(), x = rd(); for (int i = 1; i <= n; i++) a[i] = rd();
i64 sum = 0; for (int i = 1; i <= n; i++) sum += a[i]; if (sum < (n - 1) * x) return puts("NO"), 0;
for (int i = 1; i <= n; i++) fa[i] = i; int ect = 0; for (int i = 1; i <= m; i++) { int u = rd(), v = rd(); int fu = find(u), fv = find(v); if (fu == fv) continue; ect++, fa[fu] = fv; g[u].emplace_back(v, i); g[v].emplace_back(u, i); } if (ect != n - 1) return puts("NO"), 0;
hd = 1, tl = n - 1, dfs(1, 0);
puts("YES"); for (int i = 1; i <= n - 1; i++) { printf("%d\n", ans[i]); } return 0; }
|