Submission #545779

# Submission time Handle Problem Language Result Execution time Memory
545779 2022-04-05T12:40:43 Z Jomnoi Crocodile's Underground City (IOI11_crocodile) C++17
100 / 100
684 ms 64472 KB
#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;

const int MAX_N = 1e5 + 10;
const int INF = 1e9 + 7;

int dist1[MAX_N], dist2[MAX_N];
vector <pair <int, int>> adj[MAX_N];
bool visited[MAX_N];

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
    for(int i = 1; i <= N; i++) {
        dist1[i] = dist2[i] = INF;
    }
    for(int i = 0; i < M; i++) {
        R[i][0]++, R[i][1]++;
        adj[R[i][0]].emplace_back(R[i][1], L[i]);
        adj[R[i][1]].emplace_back(R[i][0], L[i]);
    }

    priority_queue <pair <int, int>> pq;
    for(int i = 0; i < K; i++) {
        P[i]++;
        dist1[P[i]] = dist2[P[i]] = 0;
        pq.emplace(0, P[i]);
    }
    while(!pq.empty()) {
        int u = pq.top().second;
        pq.pop();

        if(visited[u] == true) {
            continue;
        }
        visited[u] = true;
        for(auto [v, w] : adj[u]) {
            if(visited[v] == true) {
                continue;
            }

            if(dist2[u] + w <= dist1[v]) {
                dist2[v] = dist1[v];
                dist1[v] = dist2[u] + w;
            }
            else if(dist2[u] + w < dist2[v]) {
                dist2[v] = dist2[u] + w;
            }

            if(dist2[v] != INF) {
                pq.emplace(-dist2[v], v);
            }
        }
    }
    return dist2[1];
}


# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 2 ms 2680 KB Output is correct
7 Correct 3 ms 2676 KB Output is correct
8 Correct 2 ms 2772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 2 ms 2680 KB Output is correct
7 Correct 3 ms 2676 KB Output is correct
8 Correct 2 ms 2772 KB Output is correct
9 Correct 5 ms 2900 KB Output is correct
10 Correct 3 ms 2644 KB Output is correct
11 Correct 3 ms 2792 KB Output is correct
12 Correct 8 ms 3160 KB Output is correct
13 Correct 7 ms 3320 KB Output is correct
14 Correct 2 ms 2604 KB Output is correct
15 Correct 3 ms 2716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 2 ms 2680 KB Output is correct
7 Correct 3 ms 2676 KB Output is correct
8 Correct 2 ms 2772 KB Output is correct
9 Correct 5 ms 2900 KB Output is correct
10 Correct 3 ms 2644 KB Output is correct
11 Correct 3 ms 2792 KB Output is correct
12 Correct 8 ms 3160 KB Output is correct
13 Correct 7 ms 3320 KB Output is correct
14 Correct 2 ms 2604 KB Output is correct
15 Correct 3 ms 2716 KB Output is correct
16 Correct 684 ms 64472 KB Output is correct
17 Correct 72 ms 13748 KB Output is correct
18 Correct 87 ms 15340 KB Output is correct
19 Correct 648 ms 63292 KB Output is correct
20 Correct 399 ms 53860 KB Output is correct
21 Correct 37 ms 7632 KB Output is correct
22 Correct 379 ms 46136 KB Output is correct