Submission #1069703

# Submission time Handle Problem Language Result Execution time Memory
1069703 2024-08-22T08:24:22 Z thangdz2k7 Cyberland (APIO23_cyberland) C++17
68 / 100
352 ms 10588 KB
#include <bits/stdc++.h>
#define db double

using namespace std;

const db inf = 1e18;
const db mid = 2.0;

db solve(int N, int M, int K, int H, vector <int> x, vector <int> y, vector <int> c, vector <int> arr){
    K = min(K, 100);

    vector <vector <int>> adj(N);
    for (int i = 0; i < M; ++ i) adj[x[i]].push_back(i), adj[y[i]].push_back(i);
    vector <db> dp(N, inf);
    dp[0] = 0.0; db ans = inf;

    for (int loops = 0; loops <= K; ++ loops){
        priority_queue <pair <db, int>> qu;
        vector <db> rd(N, inf);
        for (int u = 0; u < N; ++ u){
            if (dp[u] == inf || (u > 0 && arr[u] == 1)) continue;
            if (arr[u] == 0) rd[u] = 0.0;
            qu.push({-dp[u] / mid, u});
        }

        while (qu.size()){
            auto [du, u] = qu.top();
            qu.pop(); du = -du;
            if (u == H) continue;
            for (int id : adj[u]){
                int v = x[id] ^ y[id] ^ u;
                if (rd[v] > du + c[id]){
                    rd[v] = du + c[id];
                    qu.push({-rd[v], v});
                }
            }
        }

        if (!loops && rd[H] == inf) break;
        dp = rd;
        ans = min(ans, dp[H]);
    }

    if (ans == inf) return -1;
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 33 ms 452 KB Correct.
2 Correct 30 ms 344 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 85 ms 564 KB Correct.
2 Correct 73 ms 556 KB Correct.
3 Correct 84 ms 548 KB Correct.
4 Correct 68 ms 344 KB Correct.
5 Correct 67 ms 596 KB Correct.
6 Correct 148 ms 1420 KB Correct.
7 Correct 187 ms 1256 KB Correct.
8 Correct 86 ms 2492 KB Correct.
9 Correct 71 ms 344 KB Correct.
10 Correct 52 ms 600 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 111 ms 348 KB Correct.
2 Correct 91 ms 560 KB Correct.
3 Correct 84 ms 588 KB Correct.
4 Correct 80 ms 344 KB Correct.
5 Correct 107 ms 512 KB Correct.
6 Correct 38 ms 1372 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 110 ms 6800 KB Correct.
2 Correct 94 ms 584 KB Correct.
3 Correct 109 ms 604 KB Correct.
4 Correct 91 ms 592 KB Correct.
5 Correct 68 ms 516 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 37 ms 596 KB Correct.
2 Correct 47 ms 540 KB Correct.
3 Correct 44 ms 344 KB Correct.
4 Correct 106 ms 1196 KB Correct.
5 Correct 38 ms 348 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 84 ms 596 KB Correct.
2 Correct 49 ms 600 KB Correct.
3 Correct 37 ms 7760 KB Correct.
4 Correct 67 ms 1204 KB Correct.
5 Correct 51 ms 344 KB Correct.
6 Correct 51 ms 552 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 95 ms 584 KB Correct.
2 Correct 19 ms 348 KB Correct.
3 Incorrect 352 ms 10528 KB Wrong Answer.
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 239 ms 348 KB Correct.
2 Correct 38 ms 344 KB Correct.
3 Correct 242 ms 10588 KB Correct.
4 Incorrect 278 ms 976 KB Wrong Answer.
5 Halted 0 ms 0 KB -