#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 fin;
set<int> zeroAccess;
vector<int> dejaVu;
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<vector<Arc>> adj;
void dfs(int n){
if(dejaVu[n] == 1)
return;
dejaVu[n] = 1;
if(n == fin){
return;
}
if(pouvoirs[n] == 0)
zeroAccess.insert(n);
for(int v=0; v<(int)adj[n].size(); v++){
dfs(adj[n][v].dest);
}
}
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
zeroAccess.clear();
zeroAccess.insert(0);
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]});
}
dfs(0);
if(!dejaVu[fin])
return -1;
vector<vector<int>> deja(N, vector<int>(K+1, 0));
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(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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 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 |
Runtime error |
3 ms |
1572 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
33660 KB |
Correct. |
2 |
Runtime error |
2 ms |
1372 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
1116 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
1372 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 |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
420 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |