# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
153105 | mhy908 | Crocodile's Underground City (IOI11_crocodile) | C++14 | 899 ms | 94340 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 "crocodile.h"
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define inf 987654321987654321
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
int n, m, k;
vector<pair<int, LL> > link[100010];
LL dijk[100010][3];
bool ch[100010];
priority_queue<pair<LL, int> >pq;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
n=N;
m=M;
k=K;
for(int i=0; i<m; i++){
link[R[i][0]+1].pb(make_pair(R[i][1]+1, (LL)L[i]));
link[R[i][1]+1].pb(make_pair(R[i][0]+1, (LL)L[i]));
}
for(int i=1; i<=n; i++)dijk[i][1]=dijk[i][2]=inf;
for(int i=0; i<k; i++)dijk[P[i]+1][1]=dijk[P[i]+1][2]=0, pq.push(make_pair(0, +P[i]+1));
while(!pq.empty()){
int here=pq.top().S;
LL c=-pq.top().F;
pq.pop();
if(ch[here])continue;
ch[here]=true;
for(int i=0; i<link[here].size(); i++){
int next=link[here][i].F;
LL cost=link[here][i].S;
if(ch[next])continue;
if(dijk[next][1]>c+cost){
dijk[next][2]=dijk[next][1];
dijk[next][1]=c+cost;
pq.push(make_pair(-dijk[next][2], next));
}
else if(dijk[next][2]>c+cost){
dijk[next][2]=c+cost;
pq.push(make_pair(-dijk[next][2], next));
}
}
}
return (int)dijk[1][2];
}
/*
5 7 2
0 2 4
0 3 3
3 2 2
2 1 10
0 1 100
0 4 7
3 4 9
1
3
14
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |