Submission #758269

# Submission time Handle Problem Language Result Execution time Memory
758269 2023-06-14T10:45:56 Z ivaziva Crocodile's Underground City (IOI11_crocodile) C++14
100 / 100
528 ms 89964 KB
#include <bits/stdc++.h>
#include "crocodile.h"

using namespace std;

#define MAXN 100010

long long n;
long long m;
long long k;
vector<pair<long long,long long>> adj[MAXN];
long long pos[MAXN];
priority_queue<pair<long long,long long>,vector<pair<long long,long long>>,greater<pair<long long,long long>>> pq;
long long dist1[MAXN];
long long dist2[MAXN];
long long niz[MAXN];

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
    n=N; m=M; k=K;
    for (long long i=1;i<=m;i++)
    {
        long long x;
        long long y;
        long long z;
        x=R[i-1][0];
        y=R[i-1][1];
        z=L[i-1];
        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;
    }
    for (long long i=1;i<=k;i++)
    {
        niz[i]=P[i-1];
        dist1[niz[i]]=0;
        dist2[niz[i]]=0;
        pq.push({0,niz[i]});
        pos[niz[i]]=1;
    }
    while (pq.empty()==false)
    {
        long long node0=pq.top().second;
        long long dist0=pq.top().first;
        pq.pop();
        if (dist2[node0]<dist0) continue;
        if (pos[node0]>1) continue;
        if (pos[node0]==1)
        {
            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]=dist+dist0;
                    pq.push({dist2[node],node});
                }
            }
        }
        pos[node0]++;
    }
    return dist2[0];
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 3 ms 4200 KB Output is correct
3 Correct 2 ms 4208 KB Output is correct
4 Correct 3 ms 4308 KB Output is correct
5 Correct 3 ms 4308 KB Output is correct
6 Correct 3 ms 4308 KB Output is correct
7 Correct 3 ms 4308 KB Output is correct
8 Correct 4 ms 4308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 3 ms 4200 KB Output is correct
3 Correct 2 ms 4208 KB Output is correct
4 Correct 3 ms 4308 KB Output is correct
5 Correct 3 ms 4308 KB Output is correct
6 Correct 3 ms 4308 KB Output is correct
7 Correct 3 ms 4308 KB Output is correct
8 Correct 4 ms 4308 KB Output is correct
9 Correct 4 ms 4564 KB Output is correct
10 Correct 2 ms 4180 KB Output is correct
11 Correct 4 ms 4340 KB Output is correct
12 Correct 6 ms 4980 KB Output is correct
13 Correct 5 ms 5056 KB Output is correct
14 Correct 3 ms 4180 KB Output is correct
15 Correct 3 ms 4372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 3 ms 4200 KB Output is correct
3 Correct 2 ms 4208 KB Output is correct
4 Correct 3 ms 4308 KB Output is correct
5 Correct 3 ms 4308 KB Output is correct
6 Correct 3 ms 4308 KB Output is correct
7 Correct 3 ms 4308 KB Output is correct
8 Correct 4 ms 4308 KB Output is correct
9 Correct 4 ms 4564 KB Output is correct
10 Correct 2 ms 4180 KB Output is correct
11 Correct 4 ms 4340 KB Output is correct
12 Correct 6 ms 4980 KB Output is correct
13 Correct 5 ms 5056 KB Output is correct
14 Correct 3 ms 4180 KB Output is correct
15 Correct 3 ms 4372 KB Output is correct
16 Correct 419 ms 86328 KB Output is correct
17 Correct 76 ms 18380 KB Output is correct
18 Correct 102 ms 20820 KB Output is correct
19 Correct 528 ms 89964 KB Output is correct
20 Correct 270 ms 69572 KB Output is correct
21 Correct 37 ms 11076 KB Output is correct
22 Correct 291 ms 65372 KB Output is correct