#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 4000005
#define ff first
#define ss second
#define pb push_back
#define sz(s) (int)s.size()
#define rep(c, a, b) for(c = a; c <= b; c++)
ll n, m, vis[N], a[N], viss[N];
vector <int> v[N];
vector <pair <int,int>> ans;
map <pair<int,int>,int> vip;
void solve(int x) {
viss[x] = 1;
for(auto i : v[x]) {
if(viss[i]) continue;
solve(i);
ans.pb({vip[{x,i}],vis[i]});
vis[x] -= vis[i];
}
}
int main () {
ios::sync_with_stdio(0);cin.tie(0);
cin >> n >> m;
for(int i = 1;i <= n; i++) {
cin >> a[i];
vis[i] = a[i];
}
for(int i = 1;i <= m; i++) {
ll x, y;
cin >> x >> y;
v[x].pb(y);
v[y].pb(x);
vip[{x,y}] = i;
vip[{y,x}] = i;
}
if(n > m) {
cout << '0' << '\n';
return 0;
}
solve(1);
sort(ans.begin(),ans.end());
for(auto i:ans) {
cout << i.ss * 2 << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |