Submission #970354

# Submission time Handle Problem Language Result Execution time Memory
970354 2024-04-26T12:06:27 Z anton Cyberland (APIO23_cyberland) C++17
44 / 100
33 ms 11756 KB
#include "cyberland.h"
#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define int long long
#define pii pair<int, int>

void find_resets(int u, vector<bool>& vis, vector<vector<pii>>& adj, vector<int>& resets, vector<signed>& arr){
    vis[u] = true;
    if(arr[u] == 0){
        resets.push_back(u);
    }
    for(auto e: adj[u]){
        if(!vis[e.first]){
            find_resets(e.first, vis, adj, resets, arr);
        }
    }
}

int find_closest(vector<vector<pii>>& adj, vector<int>& resets, int h){
    priority_queue<pii> pq;
        vector<int> dist(adj.size(), 1e18);

    for(auto e: resets){
        pq.push({0, e});

        dist[e] = 0;
    }


    while(pq.size()>0){
        auto curid = pq.top().second;
        int curdist=  -pq.top().first;
        pq.pop();
        if(curdist == dist[curid]){
            for(auto e: adj[curid]){
                int ndist = curdist + e.second;
                if(ndist<dist[e.first]){
                    dist[e.first] = ndist;
                    pq.push({-ndist, e.first});
                }
            }
        }
    }

    if(dist[h] == 1e18){
        return -1;
    }
    else{
        return dist[h];
    }
}

double solve(signed N, signed M, signed K, signed H, std::vector<signed> x, std::vector<signed> y, std::vector<signed> c, std::vector<signed> arr) {
    vector<vector<pii>> adj(N);
    for(int i = 0; i<M; i++){
        adj[x[i]].push_back({y[i], c[i]});
        adj[y[i]].push_back({x[i], c[i]});
    }
    vector<int> res(N);
    vector<bool> vis(N);
    vis[H] = true;
    vector<int> resets;
    arr[0] = 0;
    find_resets(0, vis, adj, resets, arr);
    return (double)(find_closest(adj, resets, H));
    
    return -1;
}
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 600 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 604 KB Correct.
2 Correct 23 ms 600 KB Correct.
3 Correct 21 ms 604 KB Correct.
4 Correct 24 ms 604 KB Correct.
5 Correct 22 ms 604 KB Correct.
6 Correct 19 ms 1548 KB Correct.
7 Correct 24 ms 1440 KB Correct.
8 Correct 10 ms 2908 KB Correct.
9 Correct 22 ms 544 KB Correct.
10 Correct 21 ms 348 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 28 ms 600 KB Correct.
2 Correct 25 ms 1396 KB Correct.
3 Correct 22 ms 1332 KB Correct.
4 Correct 25 ms 1368 KB Correct.
5 Correct 23 ms 1384 KB Correct.
6 Correct 5 ms 1788 KB Correct.
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 8544 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 604 KB Correct.
2 Correct 23 ms 1632 KB Correct.
3 Correct 22 ms 1660 KB Correct.
4 Correct 20 ms 2748 KB Correct.
5 Correct 19 ms 1116 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 21 ms 600 KB Correct.
2 Correct 19 ms 1624 KB Correct.
3 Correct 33 ms 11756 KB Correct.
4 Correct 13 ms 2228 KB Correct.
5 Correct 26 ms 1420 KB Correct.
6 Correct 21 ms 1628 KB Correct.
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 604 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 600 KB Wrong Answer.
2 Halted 0 ms 0 KB -