This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <set>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <complex>
#include <stack>
#include <set>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define ll long long int
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define cd complex<double>
const int INF = 1e9;
using namespace std;
const int MAXN = 100*1000 +5;
int nodeVal[MAXN];
int edgesVal[MAXN];
bool marked[MAXN];
vector<ii> g[MAXN];
void dfs(int node,int p,int pe){
for(auto e:g[node]){
if(e.ff != p){
dfs(e.ff,node,e.ss);
nodeVal[node] -= nodeVal[e.ff];
}
}
if(pe > -1){
edgesVal[pe] = nodeVal[node];
}
}
int main(){
int n,m;
cin >> n >> m;
if(m > n){
cout << "0" << endl;
}else if(m < n){
FOR(i,n)cin >> nodeVal[i];
FOR(i,m){
int a,b;
cin >> a >> b;
a--;b--;
g[a].pb({b,i});
g[b].pb({a,i});
}
dfs(0,-1,-1);
FOR(i,m){
cout << 2*edgesVal[i] << endl;
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |