# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
758257 | ivaziva | Crocodile's Underground City (IOI11_crocodile) | C++14 | 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 "crocodile.h"
#include <bits/stdc++.h>
#define MAXN 1010
int travel_plan(int N,int M,int R[][2],int L[],int K,int P[])
{
long long n;
long long m;
long long k;
vector<pair<long long long>> adj[MAXN];
long long niz[MAXN];
long long dist1[MAXN];
long long dist2[MAXN];
long long pos[MAXN];
n=N; m=M; k=K;
for (long long i=0;i<m;i++)
{
long long x=R[i][0];
long long y=R[i][1];
long long z=L[i];
adj[x].push_back({y,z});
adj[y].push_back({x,z});
}
for (long long i=0;i<MAXN;i++)
{
dist1[i]=LLONG_MAX;
dist2[i]=LLONG_MAX;
}
priority_queue<pair<long long,long long>,vector<pair<long long,long long>>,greater<pair<long long,long long>>> pq;
for (long long i=0;i<k;i++)
{
niz[i+1]=P[i-1];
pq.push({0,niz[i+1]});
dist1[niz[i+1]]=0;
dist2[niz[i+1]]=0;
pos[niz[i+1]]=1;
}
while (pq.empty()==false)
{
long long node=pq.top().second;
long long dist0=pq.top().first;
pq.pop();
if (dist0>dist2[node0]) continue;
if (pos[node]>1) continue;
long long s=adj[node0].size();
for (long long i=0;i<s;i++)
{
long long node=adj[node0][i].first;
long long dist=adj[node0][i].second;
if (dist0+dist<dist1[node])
{
dist2[node]=dist1[node];
dist1[node]=dist0+dist;
pq.push({dist1[node],node});
}
else if (dist0+dist<dist2[node])
{
dist2[node]=dist0+dist;
pq.push({dist2[node],node});
}
}
pos[node0]++;
}
return (int)dist2[0];
}