#include <bits/stdc++.h>   struct Edge {     int u, v;     int w;   };   struct RowEdges {     int sum;     std::vector<Edge> vs;     RowEdges() : sum(0) {}     Edge &back() { return vs.back(); }     Edge &front() { return vs.front(); }     Edge &operator[](int i) { return vs[i]; }     int size() { return (int)vs.size(); }     void pop_back() { vs.pop_back(); }     void push_back(Edge ae) { vs.push_back(ae); }     bool operator<(RowEdges ot) const { return sum < ot.sum; }   };   struct Graph {     Graph(int n) : ves(n), vals(nullptr) {}     ~Graph() {       if (vals) {         delete[] vals;         vals = nullptr;       }     }     void addTwoEdge(int a, int b, int awei = 0, int bwei = 0) {       int minWei = std::min(awei, bwei);       addEdge(a, b, minWei);       addEdge(b, a, minWei);     }     void removeTwoEdge(int a, int b) {       removeEdge(a, b);       removeEdge(b, a);     }     void removeEdge(int a, int b) {       auto &tv = ves[a];       for (int i = 0; i < (int)tv.size(); i++) {         if (tv[i].v == b) {           tv.sum -= std::min(vals[a], vals[b]);           tv[i] = tv.back();           tv.pop_back();           break;         }       }     }     void addEdge(int a, int b, int addWeight = 0) {       ves[a].push_back(Edge());       auto &bn = ves[a].back();       bn.u = a, bn.v = b;       ves[a].sum += addWeight;     }     void sort(int off = 0) {       std::sort(ves.begin() + off, ves.end());       std::vector<int> oldToNewId(ves.size());       std::vector<int> newToOldId(ves.size());       for (size_t i = off; i < ves.size(); i++) {         if (ves[i].size()) {           oldToNewId[ves[i].front().u] = i;           newToOldId[i] = ves[i].front().u;         }       }       for (size_t i = off; i < ves.size(); i++) {         for (int j = 0; j < ves[i].size(); j++) {           ves[i][j].u = oldToNewId[ves[i][j].u];           ves[i][j].v = oldToNewId[ves[i][j].v];         }       }       int n = ves.size();       int *varr = new int[n];       memcpy(varr, vals, n * sizeof(int));       for (int i = off; i < n; i++) {         int j = newToOldId[i];         vals[i] = varr[j];       }       delete[] varr;     }     int getAns() {       int ans = 0;       for (size_t i = 1; i < ves.size(); i++) {         sort(i);         if (ves[i].size()) {           ans += ves[i].sum;           while (ves[i].size()) {             removeTwoEdge(i, ves[i].front().v);           }         }       }       return ans;     }     std::vector<RowEdges> ves;     int *vals;   };   int main() {     int n = 0, m = 0, n1 = 0;     scanf( %d %d , &n, &m);     n1 = n + 1;     int *v = new int[n1];     v[0] = 0;     for (int i = 1; i < n1; i++) {       scanf( %d , v + i);     }     Graph g(n1);     g.vals = v;     int a = 0, b = 0;     for (int i = 0; i < m; i++) {       scanf( %d %d , &a, &b);       g.addTwoEdge(a, b, v[a], v[b]);     }     printf( %d , g.getAns());     return 0;   }   