#include using namespace std; #define int long long const int p=998244353; int po(int a,int b) {if(b==0) return 1; if(b==1) return a; if(b%2==0) {int u=po(a,b/2);return (u*1LL*u)%p;} else {int u=po(a,b-1);return (a*1LL*u)%p;}} int inv(int x) {return po(x,p-2);} mt19937 rnd; #define app push_back #define all(x) (x).begin(),(x).end() #ifdef LOCAL #define debug(...) [](auto...a){ ((cout << a << ' '), ...) << endl;}(#__VA_ARGS__, ":", __VA_ARGS__) #define debugv(v) do {cout<< #v <<" : {"; for(int izxc=0;izxc,int> add; vector g[maxn]; bool used[maxn];int col[maxn];int s=0; void dfs(int x) { used[x]=true; if(!col[x]) {s+=c[x];s%=p;} else {s-=c[x];s%=p;} for(int v:g[x]) { if(!used[v]) { col[v]=(col[x]^1); dfs(v); } } } const int inv2=(p+1)/2; void dfs2(int x) { used[x]=true; for(int v:g[x]) { if(!used[v]) { dfs2(v); add[{x,v}]-=c[v];add[{x,v}]%=p; c[x]-=c[v];c[x]%=p;c[v]=0; } } } int32_t main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n,m;cin>>n>>m; for(int i=0;i>c[i];} vector > ed;vector res(m); map,int> id; for(int i=0;i>x>>y;--x;--y; ed.app({x,y}); g[x].app(y);g[y].app(x); id[{x,y}]=i;id[{y,x}]=i; } dfs(0); for(auto [x,y]:ed) { if(col[x]==col[y]) { if(col[x]==0) { add[{x,y}]+=(-s*inv2)%p; c[x]-=(s*inv2)%p; c[y]-=(s*inv2)%p; } else { add[{x,y}]+=(s*inv2)%p; c[x]+=(s*inv2)%p; c[y]+=(s*inv2)%p; } s=0; break; } } if(s) { cout<<(-1);return 0; } fill(used,used+n,false); dfs2(0); for(int i=0;i