#include #include using namespace std; using namespace atcoder; using ll=long long; using ld=long double; ld pie=3.141592653589793; ll inf=10010010010010010; ll mod=998244353; struct unionfind { vectorpar,siz; unionfind(ll n): par(n,-1),siz(n,1){} ll root(ll x){ if (par[x]==-1) { return x; }else{ return par[x]=root(par[x]); } } bool issame(ll x,ll y){ return root(x)==root(y); } bool unite(ll x,ll y){ x=root(x); y=root(y); if (x==y) { return false; } if (siz[x]> n >> m; unionfind uf(n); vectormemo(n,0); vector>g(n); for (ll i = 0; i > a >> b; a--,b--; uf.unite(a,b); g[a].push_back(b); g[b].push_back(a); } vectorc(n); for (ll i = 0; i < n; i++) { cin >> c[i]; memo[uf.root(i)]+=c[i]; } bool ok=true; for (ll i = 0; i < n; i++) { if (memo[i]%2) { ok=false; } } if (!ok) { cout << -1 << endl; return 0; } map,ll>mm; for (ll i = 0; i < n; i++) { if (c[i]==0) { continue; } queueque; que.push(i); vectormemo(n,inf); memo[i]=0; while (!que.empty()) { ll v=que.front(); que.pop(); for (ll j = 0; j < g[v].size(); j++) { if (memo[g[v][j]]>memo[v]+1) { memo[g[v][j]]=memo[v]+1; que.push(g[v][j]); } } } ll now=inf,id; for (ll j = i+1; j < n; j++) { if (c[j]==1&&memo[j]