답안 #1010177

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1010177 2024-06-28T12:35:26 Z stdfloat 악어의 지하 도시 (IOI11_crocodile) C++17
46 / 100
2 ms 4700 KB
#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;

#define ff  first
#define ss  second
#define pii pair<int, int>

using ll = long long;

vector<bool> vis;

vector<ll> v, dis;

vector<vector<pii>> E;

void dfs(int x, int p = -1) {
    vis[x] = true;

    if (!dis[x]) return v[x] = 0, void();

    ll mn = LLONG_MAX;
    for (auto [i, w] : E[x]) {
        if (!vis[i]) {
            dfs(i, x);
            if (v[i] != LLONG_MAX) mn = min(mn, w + v[i]);
        }
    }

    vector<ll> u, t;
    for (auto [i, w] : E[x]) {
        if (i != p && v[i] != LLONG_MAX) (mn != w + v[i] ? u : t).push_back(v[i] + w);
    }

    if (1 < (int)t.size()) u.insert(u.end(), t.begin(), t.end());

    // cout << "x " << x << "  ";
    // for (auto i : u) cout << i << ' ';
    // cout << "   ";
    // for (auto i : t) cout << i << ' ';
    // cout << "\n";

    if (!u.empty()) v[x] = *min_element(u.begin(), u.end());
}

int travel_plan(int n, int M, int R[][2], int L[], int K, int P[]) {
    E.assign(n, {});
    for (int i = 0; i < M; i++) {
        E[R[i][0]].push_back({R[i][1], L[i]});
        E[R[i][1]].push_back({R[i][0], L[i]});
    }

    dis.assign(n, LLONG_MAX);
    priority_queue<pair<ll, int>> q;
    for (int i = 0; i < K; i++) {
        dis[P[i]] = 0;
        q.push({0, P[i]});
    }
    while (!q.empty()) {
        auto [d, x] = q.top(); d = -d; q.pop();
    
        if (d != dis[x]) continue;

        for (auto [i, w] : E[x]) {
            if (d + w < dis[i]) {
                dis[i] = d + w;
                q.push({-dis[i], i});
            }
        }
    }

    vis.assign(n, false);
    v.assign(n, LLONG_MAX);
    dfs(0);

    // cout << dis[0] << endl;

    return (v[0] == LLONG_MAX ? -1 : v[0]);
}
# 결과 실행 시간 메모리 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 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4556 KB Output is correct
8 Correct 1 ms 4696 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 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4556 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Incorrect 2 ms 4700 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4556 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Incorrect 2 ms 4700 KB Output isn't correct
10 Halted 0 ms 0 KB -