#include <bits/stdc++.h>
#include "cyberland.h"
using namespace std;
#define ld long double
#define pii pair<int,int>
#define ll long long
#define rep(i,a,b) for(int i = a; i <= b; i++)
const ll INF = 1e18+10;
using z = pair<ld,pii>;
double solve(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr) {
K=min(K,30);
vector<vector<ld>> dist(N, vector<ld>(K,INF));
vector<vector<bool>> vis(N, vector<bool>(K,0LL));
vector<vector<pii>> g(N);
rep(i,0,M-1) {
g[x[i]].emplace_back(y[i],c[i]);
g[y[i]].emplace_back(x[i],c[i]);
}
priority_queue<z,vector<z>,greater<z>> pq;
dist[0][0] = 0;
pq.push({0,{0,0}});
while (!pq.empty()) {
auto [d,f] = pq.top();pq.pop();
int u = f.first;
int ck = f.second;
if(vis[u][ck]) continue;
//cout << u << ' ' << d << ' ' << ck << '\n';
vis[u][ck] = 1;
if(u==H) continue;
for(auto &[v,w] : g[u]) {
int cck = ck;
ld nd = d;
if(arr[u] == 2 && ck<K-1) {
nd /= 2;
cck++;
}
if (arr[u] == 0) nd = 0;
nd+=w;
if (nd >= dist[v][cck]) continue;
dist[v][cck] = nd;
pq.push({dist[v][cck],{v,cck}});
}
}
ld ans = INF;
rep(i,0,K-1) ans = min(ans,dist[H][i]);
if(ans == INF) return -1;
return ans;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |