Submission #219766

#TimeUsernameProblemLanguageResultExecution timeMemory
219766Andrei_CotorCrocodile's Underground City (IOI11_crocodile)C++11
89 / 100
662 ms61320 KiB
#include"crocodile.h"
#include<vector>
#include<queue>

using namespace std;

vector<pair<int,int> > Adj[100005];
int Dist[2][100005];

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
    for(int i=0; i<M; i++)
    {
        Adj[R[i][0]].push_back({R[i][1],L[i]});
        Adj[R[i][1]].push_back({R[i][0],L[i]});
    }

    for(int i=0; i<N; i++)
        Dist[0][i]=Dist[1][i]=1000000000;

    priority_queue<pair<int,int> > Q;
    for(int i=0; i<K; i++)
    {
        Dist[0][P[i]]=Dist[1][P[i]]=0;
        Q.push({0,P[i]});
    }

    while(!Q.empty())
    {
        int cost=-Q.top().first;
        int nod=Q.top().second;
        Q.pop();

        if(cost!=Dist[1][nod])
            continue;

        for(auto other:Adj[nod])
        {
            int newCost=cost+other.second;
            if(newCost<Dist[0][other.first])
            {
                int aux=Dist[0][other.first];
                Dist[0][other.first]=newCost;

                if(aux!=1000000000)
                {
                    Dist[1][other.first]=aux;
                    Q.push({-aux,other.first});
                }
            }
            else if(newCost<Dist[1][other.first])
            {
                Dist[1][other.first]=newCost;
                Q.push({-newCost,other.first});
            }
        }
    }

    return Dist[1][0];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...