답안 #995986

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
995986 2024-06-10T06:37:31 Z 54skyxenon 악어의 지하 도시 (IOI11_crocodile) C++17
100 / 100
1546 ms 125996 KB
// https://oj.uz/problem/view/IOI11_crocodile

// #define LOCAL_TESTING 1

/** Needed for linking!!! */

#ifndef LOCAL_TESTING
#include "crocodile.h"
#endif

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define INF (ll)1e18

vector<map<int, int>> graph;
vector<bool> is_exit;
vector<set<int>> visited;

ll dijkstra() {
    vector<vector<ll>> dist(graph.size(), {INF, INF});
    priority_queue<pair<ll, ll>> pq;

    for (ll i = 0; i < graph.size(); i++) {
        if (is_exit[i]) {
            pq.push({0, i});
            dist[i][0] = dist[i][1] = 0;
        }
    }

    while (pq.size()) {
        auto [d, u] = pq.top();
        pq.pop();
        d = -d;

        if (d > dist[u][1]) {
            continue;
        }

        for (auto& [v, w] : graph[u]) {
            ll cost = w + d;

            if (cost < dist[v][0]) {
                if (dist[v][0] != dist[v][1] && dist[v][0] < INF) {
                    dist[v][1] = dist[v][0];
                    pq.push({-dist[v][1], v});
                }
                dist[v][0] = cost;
            }
            else if (cost < dist[v][1]) {
                dist[v][1] = cost;
                pq.push({-cost, v});
            }
        }
    }

    return dist[0][1];
}

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
    graph.resize(N);
    is_exit.resize(N);
    visited.resize(N);

    for (int i = 0; i < M; i++) {
        graph[R[i][0]][R[i][1]] = graph[R[i][1]][R[i][0]] = L[i];
    }

    for (int i = 0; i < K; i++) {
        is_exit[P[i]] = true;
    }
        
    return dijkstra();
}

#ifdef LOCAL_TESTING

/**
 * 0 2
0 3
3 2
2 1
0 1
0 4
3 4

L=
4
3
2
10
100
7
9
P= 1
3
 */
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n = 5;
    int m = 7;
    int k = 2;

    int r[7][2] = {
        {0, 2},
        {0, 3},
        {3, 2},
        {2, 1},
        {0, 1},
        {0, 4},
        {3, 4},
    };

    int l[7] = {4, 3, 2, 10, 100, 7, 9};

    int p[2] = {1, 3};

    cout << travel_plan(n, m, r, l, k, p) << endl;
}

#endif

Compilation message

crocodile.cpp: In function 'long long int dijkstra()':
crocodile.cpp:25:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::map<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (ll i = 0; i < graph.size(); i++) {
      |                    ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 3 ms 4956 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 5 ms 5468 KB Output is correct
13 Correct 4 ms 5468 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 3 ms 4956 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 5 ms 5468 KB Output is correct
13 Correct 4 ms 5468 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1546 ms 114736 KB Output is correct
17 Correct 64 ms 38056 KB Output is correct
18 Correct 96 ms 38992 KB Output is correct
19 Correct 1477 ms 125996 KB Output is correct
20 Correct 629 ms 106832 KB Output is correct
21 Correct 42 ms 17236 KB Output is correct
22 Correct 434 ms 101564 KB Output is correct