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 66 67 68 69 70 71 72 73
| #include<bits/stdc++.h> #define PII pair<int, LL> #define LL long long using namespace std; template <class T> inline void read(T &res) { res = 0; bool flag = 0; char c = getchar(); while(c < '0' || '9' < c) {if(c == '-') flag = 1; c = getchar();} while('0' <= c && c <= '9') res = (res << 3) + (res << 1) + (c ^ 48), c = getchar(); if(flag) res = -res; } template <class T, class ...ARC> inline void read(T &res, ARC &...com){ read(res), read(com...); } template <class T> void write(T res) { if(res < 0) putchar('-'), res = -res; if(res > 9) write(res / 10); putchar(res % 10 + '0'); } template <> inline void write(char c) { putchar(c); } template <> inline void write(char *s) { while(*s) putchar(*s ++);} template <class T, class ...ARC> inline void write(T res, ARC ...com) { write(res), write(com...); } const int N = 3e5 + 5; int n, m; int a[N]; int ans[N << 1], cnt; bool vis[N]; int idx = 1; int e[N << 1], ne[N << 1], h[N]; inline void add(int x, int y) { idx ++; e[idx] = y, ne[idx] = h[x], h[x] = idx; } bool dfs(int x) { vis[x] = 1; bool res = a[x]; for(int i = h[x], j; ~i;i = ne[i]) { j = e[i]; if(vis[j]) continue; if(dfs(j)) ans[++ cnt] = i / 2, res ^= 1; } if(a[x] == -1) res = 0; return res; } int main() { memset(h, -1, sizeof(h)); read(n, m); int id = 0, flag = 0; for(int i = 1;i <= n;i ++) { read(a[i]); if(a[i] == -1) id = i; else flag ^= a[i]; } for(int i = 1, o, u;i <= m;i ++) read(o, u), add(o, u), add(u, o); if(!id && flag) return puts("-1"), 0; id = max(id, 1); dfs(id); write(cnt, '\n'); sort(ans + 1, ans + cnt + 1); for(int i = 1;i <= cnt;i ++) write(ans[i], '\n'); return 0; }
|