#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pb push_back
#define pa pair<int, int>
#define pall pair<ll, int>
#define fi first
#define se second
#define TASK "test"
#define all(x) x.begin(), x.end()
using namespace std;
template<typename T1, typename T2> bool mini (T1 &a, T2 b) {if(a > b) a = b; else return 0; return 1;}
template<typename T1, typename T2> bool maxi (T1 &a, T2 b) {if(a < b) a = b; else return 0; return 1;}
const int MOD = 1e9 + 7;
const int LOG = 20;
const int maxn = 2e5 + 7;
const ll oo = 1e17 + 69;
int n, m, r[maxn][2], l[maxn], k, p[maxn];
int travel_plan(int n, int m, int r[][2], int l[], int k, int p[])
{
ll f[n][2];
int trace[n][2];
priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> q;
memset(f, 0x3f, sizeof f);
memset(trace, -1, sizeof trace);
for(int i = 0; i < k; i++) {
f[p[i]][0] = 0;
q.push({0, p[i]});
}
vector<pair<int, int>> g[n];
for(int i = 0; i < m; i++) {
int u = r[i][0], v = r[i][1];
g[u].push_back({v, l[i]});
g[v].push_back({u, l[i]});
}
while(!q.empty()) {
int u = q.top().second;
long long fu = q.top().first;
q.pop();
if(fu > f[u][1]) continue;
for(auto e:g[u]) {
int v = e.first, w = e.second;
if(f[v][0] == 0) continue;
if(trace[u][0] == v || trace[u][1] == v) continue;
if(f[v][0] > fu + w) {
f[v][1] = f[v][0];
trace[v][1] = trace[v][0];
f[v][0] = fu + w;
trace[v][0] = u;
q.push({fu + w, v});
} else if(f[v][1] > fu + w) {
f[v][1] = fu + w;
trace[v][1] = u;
q.push({fu + w, v});
}
}
}
int res = 0, u = 0;
vector<int> path;
while(trace[u][1] != -1) {
path.pb(u);
u = trace[u][1];
}
path.pb(u);
for(int i = 0; i < (int) path.size() - 1; i++) {
int u = path[i], v = path[i + 1];
for(auto e:g[u]) {
if(e.first == v) res += e.second;
}
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//freopen(TASK".inp", "r", stdin);
//freopen(TASK".out", "w", stdout);
cin>>n>>m;
for(int i = 0; i < m; i++) cin>>r[i][0]>>r[i][1];
for(int i = 0; i < m; i++) cin>>l[i];
cin>>k;
for(int i = 0; i < k; i++) cin>>p[i];
cout<<travel_plan(n, m, r, l, k, p);
return 0;
}
Compilation message
/usr/bin/ld: /tmp/ccIPiA69.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccuRt87a.o:crocodile.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status