Submission #1023225

# Submission time Handle Problem Language Result Execution time Memory
1023225 2024-07-14T13:40:52 Z nam6 Cyberland (APIO23_cyberland) C++17
0 / 100
34 ms 33596 KB
#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std; 
 
const long long INFINI = 1e17; 
const int MAXI_K = 70; 

vector<int> pouvoirs; 
vector<int> dejaVu;
set<int> zeroAccess; 
int fin;

struct Arc{
    int dest; 
    int poids; 
};
vector<vector<Arc>> adj;
 
struct Sit{
    int node; 
    int nbDiv; 
    double dis; 
    bool operator <(const Sit &other) const{
        return dis > other.dis; 
    }
};
 
void dfs(int n){
    if(dejaVu[n] == 1) return; 
    dejaVu[n] = 1; 
    if(n == fin) return;
    if(pouvoirs[n] == 0) zeroAccess.insert(n);
        
    for(Arc arc : adj[n])
        dfs(arc.dest);  
}
 
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
    
    pouvoirs = arr; 
    fin = H;;  
    K = min(K, MAXI_K);

    dejaVu = vector<int>(N, 0);
    adj = vector<vector<Arc>>(N);

    for(int n=0; n<N; n++){
        adj[x[n]].push_back({y[n], c[n]}); 
        adj[y[n]].push_back({x[n], c[n]}); 
    }
    zeroAccess.clear(); 
    zeroAccess.insert(0);
    dfs(0);
    if(!dejaVu[fin]) return -1;  
 
    vector<vector<int>> deja(N, vector<int>(K+1)); 
    vector<vector<double>> distances(N, vector<double>(K+1, 1e17)); 
    distances[fin][0]=0;
    priority_queue<Sit> aTraiter; 
    aTraiter.push({fin, 0, 0});

    while(!aTraiter.empty()){
        Sit curSit = aTraiter.top(); 
        aTraiter.pop(); 
        if(curSit.node == fin && curSit.nbDiv != 0) continue; 
        if(deja[curSit.node][curSit.nbDiv]) continue; 
        if(zeroAccess.count(curSit.node)) return curSit.dis; 
        deja[curSit.node][curSit.nbDiv] = 1; 

        for(Arc voisin : adj[curSit.node]){
            int v = voisin.dest; 
            int w = voisin.poids; 
            
            if( distances[curSit.node][curSit.nbDiv] + (double)w/(double)pow(2, curSit.nbDiv) < distances[v][curSit.nbDiv]){
                distances[v][curSit.nbDiv] = distances[curSit.node][curSit.nbDiv] + (double)w/(double)pow(2, curSit.nbDiv);
                aTraiter.push({v, curSit.nbDiv, distances[v][curSit.nbDiv]});
            }

            if(pouvoirs[v] == 2 && curSit.nbDiv < K){
                if(distances[curSit.node][curSit.nbDiv] + (double)w/(double)pow(2, curSit.nbDiv) <  distances[v][curSit.nbDiv + 1]){
                    distances[v][curSit.nbDiv + 1] = distances[curSit.node][curSit.nbDiv] + (double)w/(double)pow(2, curSit.nbDiv);
                    aTraiter.push({v, curSit.nbDiv+1, distances[v][curSit.nbDiv + 1]});
                }
            }        
        }
    }
    return -1; 
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 452 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 1624 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 1628 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 33596 KB Correct.
2 Runtime error 2 ms 1624 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1112 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 1592 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -