답안 #583409

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
583409 2022-06-25T10:30:48 Z Drew_ 악어의 지하 도시 (IOI11_crocodile) C++17
0 / 100
3 ms 2668 KB
#include "crocodile.h"  
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define f1 first
#define s2 second

using ll = long long;
using ii = pair<int, int>;
using pl = pair<ll, ll>;

const int MAX = 1e5 + 69;
const ll inf = (ll) 1e18 + 69;

vector<ii> adj[MAX];
pl cost[MAX];
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
    for (int i = 0; i < N; ++i)
        cost[i] = { inf, inf };

    for (int i = 0; i < M; ++i)
    {
        adj[ R[i][0] ].pb({ R[i][1], L[i] });
        adj[ R[i][1] ].pb({ R[i][0], L[i] });
    }

    priority_queue<pair<pl, int>> pq;
    for (int i = 0; i < K; ++i)
    {
        cost[P[i]] = { 0, 0 };
        pq.push({ {0, 0}, P[i] });
    }

    const auto merge = [](pl x, ll y) -> pl
    {
        if (x.f1 > y) swap(x.f1, y);
        if (x.s2 > y) swap(x.s2, y);
        if (x.f1 > x.s2) swap(x.f1, x.s2);
        return x;
    };

    while (!pq.empty())
    {
        auto [C, node] = pq.top(); pq.pop();
        C.f1 = -C.f1; C.s2 = -C.s2;

        if (C != cost[node])
            continue;

        for (auto &[to, w] : adj[node])
        {
            pl nxt = merge(cost[to], C.s2 + w);
            if (nxt < cost[to])
            {
                cost[to] = nxt;
                pq.push({{-nxt.f1, -nxt.s2}, to});
            }
        }
    }

    return (int)cost[0].s2;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Incorrect 3 ms 2668 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Incorrect 3 ms 2668 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Incorrect 3 ms 2668 KB Output isn't correct
4 Halted 0 ms 0 KB -