Submission #493601

# Submission time Handle Problem Language Result Execution time Memory
493601 2021-12-12T10:35:34 Z ahmeteren Crocodile's Underground City (IOI11_crocodile) C++17
100 / 100
474 ms 61912 KB
#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;

const int NNN = 1e5 + 5;

long long dist1[NNN], dist2[NNN];
vector<pair<int, int>> vec[NNN];

int travel_plan(int n, int m, int R[][2], int L[], int K, int P[])
{
    for(int i = 0; i < n; i++)
        dist1[i] = dist2[i] = 1e12;

    for(int i = 0; i < m; i++)
    {
        int u = R[i][0], v = R[i][1], w = L[i];

        vec[u].push_back({v, w});
        vec[v].push_back({u, w}); 
    }

    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;

    for(int i = 0; i < K; i++)
    {
        q.push({0, P[i]});
        dist1[P[i]] = dist2[P[i]] = 0;
    }

    while(!q.empty())
    {
        long long node = q.top().second, dst = q.top().first;
        q.pop();

        if(dst > dist2[node])
            continue;

        for(auto p : vec[node])
        {
            long long to = p.first, w = p.second;

            if(dst + w < dist1[to])
            {
                if(dist1[to] < dist2[to])
                {
                    dist2[to] = dist1[to];
                    dist1[to] = dst + w;
                    q.push({dist2[to], to});
                }
                else
                {
                    dist2[to] = dist1[to];
                    dist1[to] = dst + w;
                }
            }
            else if(dst + w < dist2[to])
            {
                dist2[to] = dst + w;
                q.push({dist2[to], to});
            }
        }
    }

    return dist2[0];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2656 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2656 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 3 ms 2764 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2764 KB Output is correct
8 Correct 2 ms 2664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2656 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2656 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 3 ms 2764 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2764 KB Output is correct
8 Correct 2 ms 2664 KB Output is correct
9 Correct 3 ms 2892 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 3 ms 2764 KB Output is correct
12 Correct 5 ms 3276 KB Output is correct
13 Correct 4 ms 3148 KB Output is correct
14 Correct 2 ms 2660 KB Output is correct
15 Correct 2 ms 2764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2656 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2656 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 3 ms 2764 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2764 KB Output is correct
8 Correct 2 ms 2664 KB Output is correct
9 Correct 3 ms 2892 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 3 ms 2764 KB Output is correct
12 Correct 5 ms 3276 KB Output is correct
13 Correct 4 ms 3148 KB Output is correct
14 Correct 2 ms 2660 KB Output is correct
15 Correct 2 ms 2764 KB Output is correct
16 Correct 394 ms 57588 KB Output is correct
17 Correct 64 ms 14448 KB Output is correct
18 Correct 87 ms 15928 KB Output is correct
19 Correct 474 ms 61912 KB Output is correct
20 Correct 328 ms 49580 KB Output is correct
21 Correct 34 ms 7884 KB Output is correct
22 Correct 276 ms 46144 KB Output is correct