#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
inline void chmin(A &a, B b) {
  if (a > b) a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b) {
  if (a < b) a = b;
}
vector<long long> G[1000000];
vector<pair<long long, long long> > bridge;
vector<long long> articulation;
long long ord[1000000], low[1000000];
bool vis[1000000];
long long W[111111];
long long al = 0;
long long sum[111111];
long long ans[111111];
void dfs(long long v, long long p, long long &k) {
  vis[v] = true;
  sum[v] = W[v];
  ord[v] = k++;
  low[v] = ord[v];
  bool isArticulation = false;
  long long ct = 0;
  vector<long long> g;
  for (long long i = 0; i < G[v].size(); i++) {
    if (!vis[G[v][i]]) {
      ct++;
      g.push_back(G[v][i]);
      dfs(G[v][i], v, k);
      sum[v] += sum[G[v][i]];
      low[v] = min(low[v], low[G[v][i]]);
      if (~p && ord[v] <= low[G[v][i]]) isArticulation = true;
    } else if (G[v][i] != p) {
      low[v] = min(low[v], ord[G[v][i]]);
    }
  }
  if (p == -1 && ct > 1) isArticulation = true;
  if (isArticulation) {
    ans[v] = al - sum[v];
    for (auto u : g) {
      if (low[u] >= ord[v])
        chmax(ans[v], sum[u]);
      else {
        chmax(ans[v], al - sum[v] + sum[u]);
      }
    }
  } else {
    ans[v] = al - W[v];
  }
}
signed main() {
  long long N, M;
  scanf("%lld%lld", &N, &M);
  for (long long i = 0; i < (N); i++) scanf("%lld", &W[i]);
  for (long long i = 0; i < (M); i++) {
    long long a, b;
    scanf("%lld%lld", &a, &b);
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  al = accumulate(W, W + N, 0ll);
  long long k = 0;
  dfs(0, -1, k);
  for (long long i = 0; i < (N); i++) printf("%lld\n", ans[i]);
  return 0;
}
