답안 #746979

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
746979 2023-05-23T10:22:13 Z fishy15 악어의 지하 도시 (IOI11_crocodile) C++17
100 / 100
439 ms 61452 KB
#include <queue>
#include <utility>
#include <vector>

#include "crocodile.h"

using namespace std;

constexpr int INF = 0x3f3f3f3f;

pair<int, int> add_d(pair<int, int> cur_d, int new_d) {
    if (new_d <= cur_d.first) {
        cur_d.second = cur_d.first;
        cur_d.first = new_d;
    } else if (new_d < cur_d.second) {
        cur_d.second = new_d;
    }

    return cur_d;
}

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
    vector<vector<pair<int, int>>> adj(N);
    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]});
    }

    // first and second shortest distances
    vector<pair<int, int>> d(N, {INF, INF});
    vector<int> vis_count(N);

    // {second, location}
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> pq;
    for (int i = 0; i < K; i++) {
        int cur = P[i];
        d[cur] = {0, 0};
        pq.push({0, cur});
    }

    while (!pq.empty()) {
        auto [dd, t] = pq.top();
        pq.pop();

        if (d[t].second == dd) {
            for (auto [v, w] : adj[t]) {
                auto nxt_d = add_d(d[v], dd + w);
                if (nxt_d.second < d[v].second) {
                    pq.push({nxt_d.second, v});
                }
                d[v] = nxt_d;
            }
        }
    }

    return d[0].second;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 308 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 308 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 3 ms 724 KB Output is correct
13 Correct 3 ms 820 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 308 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 3 ms 724 KB Output is correct
13 Correct 3 ms 820 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 312 KB Output is correct
16 Correct 350 ms 56008 KB Output is correct
17 Correct 59 ms 14092 KB Output is correct
18 Correct 79 ms 15496 KB Output is correct
19 Correct 439 ms 61452 KB Output is correct
20 Correct 227 ms 46888 KB Output is correct
21 Correct 30 ms 6096 KB Output is correct
22 Correct 264 ms 44460 KB Output is correct