# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
526792 | zhangjishen | Crocodile's Underground City (IOI11_crocodile) | C++98 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
template<typename T> bool chkmin(T &a, T b){return b < a ? a = b, 1 : 0;}
template<typename T> bool chkmax(T &a, T b){return b > a ? a = b, 1 : 0;}
typedef long long ll;
typedef pair<int, int> pii;
const int MAXN = 1e5 + 10, inf = 2e9, MAXM = 1e6 + 10;
int n, m, k, ext[MAXN], a[MAXM], b[MAXM], c[MAXM];
int g[MAXN], f[MAXN];
vector<pii> adj[MAXN];
priority_queue<pii, vector<pii>, greater<pii> > q;
void dijkstra(){
for(int i = 1; i <= n; i++)
g[i] = f[i] = inf;
for(int i = 1; i <= k; i++){
int u = ext[i];
g[u] = f[u] = 0; q.push(mp(0, u));
}
while(!q.empty()){
pii p = q.top(); q.pop();
int u = p.se;
if(p.fi != f[u]) continue;
for(int i = 0; i < (int)adj[u].size(); i++){
int v = adj[u][i].fi, w = adj[u][i].se;
if(f[u] + w < g[v]){
f[v] = g[v];
if(f[v] != inf)
q.push(mp(f[v], v));
g[v] = f[u] + w;
}else if(chkmin(f[v], f[u] + w))
q.push(mp(f[v], v));
}
}
}
int main(){
// input
scanf("%d %d %d", &n, &m, &k);
for(int i = 1; i <= m; i++){
scanf("%d %d", &a[i], &b[i]);
a[i]++; b[i]++;
}
for(int i = 1; i <= m; i++){
scanf("%d", &c[i]);
adj[a[i]].pb(mp(b[i], c[i]));
adj[b[i]].pb(mp(a[i], c[i]));
}
for(int i = 1; i <= k; i++){
scanf("%d", &ext[i]);
ext[i]++;
}
// dijkstra
dijkstra();
printf("%d\n", f[1]);
}