#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
const long long INFINI = 1e17;
const int MAXI_NOEUDS = 100*1000 + 100;
const int MAXI_K = 70;
vector<int> pouvoirs;
int nbNoeuds, nbAretes, K, fin;
bool finAccess;
struct Arc{
int dest;
int poids;
};
struct Sit{
int node;
int nbDiv;
double dis;
bool operator <(const Sit &other) const{
return dis > other.dis;
}
};
vector<Arc> adj[MAXI_NOEUDS];
int zerosAccess[MAXI_NOEUDS];
int dejaVu[MAXI_NOEUDS];
void dfs(int n){
if(dejaVu[n] == 1)
return;
dejaVu[n] = 1;
if(n == fin){
return;
}
if(pouvoirs[n] == 0)
zerosAccess[n] = 1;
for(int v=0; v<(int)adj[n].size(); v++){
dfs(adj[n][v].dest);
}
}
priority_queue<Sit> aTraiter;
int deja[MAXI_NOEUDS][MAXI_K + 1];
double distances[MAXI_NOEUDS][MAXI_K + 1];
double djikstra(){
aTraiter.push({fin, 0, 0});
distances[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(zerosAccess[curSit.node] == 1){
return curSit.dis;
}
deja[curSit.node][curSit.nbDiv] = 1;
for(int i=0; i<(int)adj[curSit.node].size(); i++){
Arc voisin = adj[curSit.node][i];
int v = voisin.dest;
int w = voisin.poids;
// pas diviser par 2
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]});
}
// diviser par 2
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;
}
double solve(int N, int M, int k, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
pouvoirs.clear();
finAccess = false;
while(!aTraiter.empty()){
aTraiter.pop();
}
for(int i=0; i<MAXI_NOEUDS; i++){
adj[i].clear();
zerosAccess[i] = 0;
dejaVu[i] = 0;
for(int j=0; j<MAXI_K + 1; j++){
deja[i][j] = 0;
distances[i][j] = INFINI;
}
}
zerosAccess[0] = 1;
pouvoirs = arr;
fin = H;
nbNoeuds = N;
nbAretes = M;
K = min(k, MAXI_K);
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]});
}
dfs(0);
if(!dejaVu[fin])
return -1;
else
return djikstra();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
123 ms |
175952 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
121 ms |
176288 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
139 ms |
176464 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
92924 KB |
Correct. |
2 |
Runtime error |
155 ms |
176408 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
119 ms |
176208 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
106 ms |
176160 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
131 ms |
176212 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
120 ms |
176212 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |