Submission #753412

# Submission time Handle Problem Language Result Execution time Memory
753412 2023-06-05T07:33:50 Z Jomnoi Cyberland (APIO23_cyberland) C++17
0 / 100
3000 ms 26348 KB
#include <bits/stdc++.h>
#include "cyberland.h"
using namespace std;

const int MAX_N = 1e5 + 5;
const int MAX_K = 35;
const long long INF = 1e18 + 7;

vector <pair <int, int>> graph[MAX_N];
double dist[MAX_N][MAX_K];
bool visited[MAX_N][MAX_K];

double solve(int N, int M, int K, int H, vector <int> x, vector <int> y, vector <int> c, vector <int> arr) {
    for (int i = 0; i < N; i++) {
        graph[i].clear();
        for (int k = 0; k <= K; k++) {
            dist[i][k] = INF;
            visited[i][k] = false;
        }
    }

    for (int i = 0; i < M; i++) {
        graph[x[i]].emplace_back(y[i], c[i]);
        graph[y[i]].emplace_back(x[i], c[i]);
    }

    queue <int> q;
    q.push(0);
    visited[0][0] = true;
    while (!q.empty()) {
        int u = q.front();
        q.pop();

        for (auto [v, c] : graph[u]) {
            if (visited[v][0] == true or v == H) continue;

            visited[v][0] = true;
            q.push(v);
        }
    }

    priority_queue <tuple <double, int, int>> pq;
    for (int i = 0; i < N; i++) {
        if (visited[i][0] == false or arr[i] != 0) continue;
        
        pq.emplace(0, 0, i);
        dist[i][0] = 0;
        visited[i][0] = false;
    }

    while (!pq.empty()) {
        auto [d, k, u] = pq.top();
        pq.pop();

        if (visited[u][k] == true) continue;
        visited[u][k] = true;

        for (auto [v, c] : graph[u]) {
            if (v == H) continue;

            if (visited[v][k] == false and dist[u][k] + c < dist[v][k]) {
                dist[v][k] = dist[u][k] + c;
                pq.emplace(-dist[v][k], k, v);
            }
            if (arr[v] == 2 and k < K and visited[v][k + 1] == false and (dist[u][k] + c) / 2 < dist[v][k + 1]) {
                dist[v][k + 1] = (dist[u][k] + c) / 2;
                pq.emplace(-dist[v][k + 1], k + 1, v);
            }
        }
    }

    double res = INF;
    for (int k = 0; k <= K; k++) {
        for (auto [v, c] : graph[H]) {
            res = min(res, dist[v][k] + c);
        }
    }

    if (res == INF) res = -1;
    return res;
}
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 2772 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 3044 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 3028 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 134 ms 26348 KB Correct.
2 Incorrect 138 ms 3244 KB Wrong Answer.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 3156 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 3164 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 174 ms 3588 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3048 ms 12096 KB Time limit exceeded
2 Halted 0 ms 0 KB -