This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
struct edge { int a,b,c; };
bool comp(edge a,edge b) {
    return a.c < b.c;
}
edge edges[300000];
int x[20],y[20];
int P[100000];
int ds[100000];
int find(int n) {
    if (ds[n] != n) ds[n] = find(ds[n]);
    return ds[n];
}
vpii adjList[100000];
int com[100000];
int doDFS(int u,int c) {
    if (com[u] != -1) return 0;
    int i;
    com[u] = c;
    for (i = 0; i < adjList[u].size(); i++) doDFS(adjList[u][i].first,c);
    return 0;
}
LLI P2[21];
int yes[21];
int parent[21],mm[21],depth[21];
LLI size[21];
int doDFS2(int u,int p,int d) {
    int i;
    parent[u] = p,depth[u] = d,size[u] = P2[u];
    for (i = 0; i < adjList[u].size(); i++) {
        int v = adjList[u][i].first;
        if (v != p) doDFS2(v,u,d+1),size[u] += size[v];
    }
    return 0;
}
int main() {
    int i;
    int N,M,K;
    scanf("%d %d %d",&N,&M,&K);
    for (i = 0; i < M; i++) {
        scanf("%d %d %d",&edges[i].a,&edges[i].b,&edges[i].c);
        edges[i].a--,edges[i].b--;
    }
    for (i = 0; i < K; i++) scanf("%d %d",&x[i],&y[i]),x[i]--,y[i]--;
    for (i = 0; i < N; i++) scanf("%d",&P[i]);
    sort(edges,edges+M,comp);
    for (i = 0; i < N; i++) ds[i] = i;
    for (i = 0; i < K; i++) {
        int u = x[i],v = y[i];
        if (find(u) != find(v)) ds[find(u)] = find(v);
    }
    for (i = 0; i < M; i++) {
        int u = edges[i].a,v = edges[i].b;
        if (find(u) != find(v)) {
            ds[find(u)] = find(v);
            adjList[u].pb(mp(v,0));
            adjList[v].pb(mp(u,0));
        }
    }
    int c = 0,e = 0;
    fill(com,com+N,-1);
    for (i = 0; i < N; i++) {
        if (com[i] == -1) doDFS(i,c),c++;
    }
    for (i = 0; i < c; i++) ds[i] = i;
    for (i = 0; i < M; i++) {
        edges[e].a = com[edges[i].a],edges[e].b = com[edges[i].b],edges[e].c = edges[i].c;
        if (find(edges[e].a) != find(edges[e].b)) ds[find(edges[e].a)] = find(edges[e].b),e++;
    }
    for (i = 0; i < K; i++) x[i] = com[x[i]],y[i] = com[y[i]];
    for (i = 0; i < N; i++) P2[com[i]] += P[i],adjList[i].clear();
    N = c,M = e;
    int j,k;
    LLI ans = 0;
    for (i = 1; i < (1 << K); i++) {
        for (j = 0; j < N; j++) ds[j] = j;
        for (j = 0; j < K; j++) {
            if (i & (1 << j)) {
                int u = x[j],v = y[j];
                if (find(u) == find(v)) break;
                else {
                    ds[find(u)] = find(v);
                    adjList[u].pb(mp(v,1));
                    adjList[v].pb(mp(u,1));
                }
            }
        }
        if (j == K) {
            for (j = 0; j < M; j++) {
                int u = edges[j].a,v = edges[j].b;
                if (find(u) != find(v)) {
                    ds[find(u)] = find(v);
                    adjList[u].pb(mp(v,0));
                    adjList[v].pb(mp(u,0));
                    yes[j] = 0;
                }
                else yes[j] = 1;
            }
            doDFS2(0,-1,0);
            for (j = 0; j < N; j++) mm[j] = 1e9;
            for (j = 0; j < M; j++) {
                int u = edges[j].a,v = edges[j].b;
                if (yes[j]) {
                    while (u != v) {
                        if (depth[u] < depth[v]) swap(u,v);
                        mm[u] = min(mm[u],edges[j].c),u = parent[u];
                    }
                }
            }
            LLI sum = 0;
            for (j = 0; j < N; j++) {
                for (k = 0; k < adjList[j].size(); k++) {
                    int v = adjList[j][k].first;
                    if ((v != parent[j]) && adjList[j][k].second) sum += mm[v]*size[v];
                }
            }
            ans = max(ans,sum);
        }
        for (j = 0; j < N; j++) adjList[j].clear();
    }
    printf("%lld\n",ans);
    return 0;
}
Compilation message (stderr)
toll.cpp: In function 'int doDFS(int, int)':
toll.cpp:76:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < adjList[u].size(); i++) doDFS(adjList[u][i].first,c);
                 ~~^~~~~~~~~~~~~~~~~~~
toll.cpp: In function 'int doDFS2(int, int, int)':
toll.cpp:86:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < adjList[u].size(); i++) {
                 ~~^~~~~~~~~~~~~~~~~~~
toll.cpp: In function 'int main()':
toll.cpp:170:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (k = 0; k < adjList[j].size(); k++) {
                             ~~^~~~~~~~~~~~~~~~~~~
toll.cpp:95:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d",&N,&M,&K);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~
toll.cpp:97:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d",&edges[i].a,&edges[i].b,&edges[i].c);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:100:62: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (i = 0; i < K; i++) scanf("%d %d",&x[i],&y[i]),x[i]--,y[i]--;
                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
toll.cpp:101:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (i = 0; i < N; i++) scanf("%d",&P[i]);
                             ~~~~~^~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |