Submission #979472

# Submission time Handle Problem Language Result Execution time Memory
979472 2024-05-11T05:09:11 Z HappyCapybara Cyberland (APIO23_cyberland) C++17
44 / 100
44 ms 9204 KB
#include "cyberland.h"
#include<bits/stdc++.h>
using namespace std;

double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr){
    vector<vector<pair<int,int>>> g(N);
    for (int i=0; i<M; i++){
        g[x[i]].push_back({y[i], c[i]});
        g[y[i]].push_back({x[i], c[i]});
    }

    double dist = -1;
    vector<bool> seen(N, false);
    priority_queue<pair<double,int>> pq;
    pq.push({(double) 0, 0});
    while (!pq.empty()){
        double d = -pq.top().first;
        int cur = pq.top().second;
        pq.pop();
        if (cur == H){
            dist = d;
            break;
        }
        if (seen[cur]) continue;
        seen[cur] = true;
        for (pair<int,int> next : g[cur]) pq.push({-(d+next.second), next.first});
    }

    unordered_set<int> s;
    seen.clear();
    seen.resize(N, false);
    queue<int> q;
    q.push(0);
    while (!q.empty()){
        int cur = q.front();
        q.pop();
        if (cur == H) continue;
        if (seen[cur]) continue;
        seen[cur] = true;
        if (arr[cur] == 0) s.insert(cur);
        for (pair<int,int> next : g[cur]) q.push(next.first);
    }

    seen.clear();
    seen.resize(N, false);
    while (!pq.empty()) pq.pop();
    pq.push({(double) 0, H});
    while (!pq.empty()){
        double d = -pq.top().first;
        int cur = pq.top().second;
        pq.pop();
        if (s.find(cur) != s.end()){
            if (d < dist) return d;
            else break;
        }
        if (seen[cur]) continue;
        seen[cur] = true;
        for (pair<int,int> next : g[cur]) pq.push({-(d+next.second), next.first});
    }

    return dist;
}
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 600 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 604 KB Correct.
2 Correct 33 ms 600 KB Correct.
3 Correct 31 ms 348 KB Correct.
4 Correct 33 ms 344 KB Correct.
5 Correct 34 ms 592 KB Correct.
6 Correct 29 ms 1492 KB Correct.
7 Correct 44 ms 1436 KB Correct.
8 Correct 17 ms 2396 KB Correct.
9 Correct 29 ms 348 KB Correct.
10 Correct 29 ms 752 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 26 ms 604 KB Correct.
2 Correct 25 ms 1372 KB Correct.
3 Correct 27 ms 1364 KB Correct.
4 Correct 28 ms 1372 KB Correct.
5 Correct 26 ms 1372 KB Correct.
6 Correct 4 ms 1372 KB Correct.
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 5468 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 628 KB Correct.
2 Correct 31 ms 348 KB Correct.
3 Correct 35 ms 604 KB Correct.
4 Correct 35 ms 1496 KB Correct.
5 Correct 25 ms 348 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 24 ms 348 KB Correct.
2 Correct 22 ms 1284 KB Correct.
3 Correct 32 ms 9204 KB Correct.
4 Correct 14 ms 1744 KB Correct.
5 Correct 24 ms 1364 KB Correct.
6 Correct 23 ms 1368 KB Correct.
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 612 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 604 KB Wrong Answer.
2 Halted 0 ms 0 KB -