func_code_string: #include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int maxN = 1 << 18;   template <class T1, class T2>   inline void remax(T1& a, T2 b) {     a = max(a, (T1)b);   }   int deg[maxN], fat[maxN];   vector<int> G[maxN];   queue<int> Q;   long long w[maxN];   pair<long long, int> leg[2][maxN];   void solve() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = (1); i < (int)(n + 1); i++) scanf( %lld , w + i);     bool tree = m == n - 1;     while (m--) {       int a, b;       scanf( %d%d , &a, &b);       G[a].push_back(b);       G[b].push_back(a);       deg[a]++, deg[b]++;     }     int s, prv = 0;     scanf( %d , &s);     if (tree) deg[s] = maxN;     for (int i = (1); i < (int)(n + 1); i++)       if (deg[i] == 1) Q.push(i);     while (!Q.empty()) {       int v = Q.front();       Q.pop();       for (int u : G[v])         if (deg[u] > 1) {           pair<long long, int> prop = {leg[0][v].first + w[v], v};           fat[v] = u;           if (leg[0][u].first <= prop.first)             leg[1][u] = leg[0][u], leg[0][u] = prop;           else if (leg[1][u].first < prop.first)             leg[1][u] = prop;           if (--deg[u] == 1) Q.push(u);         }     }     long long res = 0, finish = 0;     while (deg[s] < 2) {       res += w[s];       remax(finish, leg[0][s].second == prv ? leg[1][s].first : leg[0][s].first);       prv = s;       s = fat[s];     }     remax(finish, leg[0][s].second == prv ? leg[1][s].first : leg[0][s].first);     for (int i = (1); i < (int)(n + 1); i++)       if (deg[i] > 1) {         res += w[i];         if (i != s) remax(finish, leg[0][i].first);       }     res += finish;     printf( %lld n , res);   }   int main() {     int t;     t = 1;     while (t--) solve();     return 0;   }   