#include <bits/stdc++.h>
#include "cyberland.h"
using namespace std;
#define ld long double
#define pii pair<ld,int>
#define ll long long
#define rep(i,a,b) for(int i = a; i <= b; i++)
const ll INF = 1e18+10;
const int MAXN = 1e5+10;
bool mk[MAXN];
void dfs(int u, vector<vector<pii>> &g, int H) {
if(mk[u]) return;
mk[u] = 1;
if (u==H) return;
for(auto &[v,w] : g[u]) dfs(v,g,H);
}
using z = pair<ld, pair<int,int>>;
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,100);
rep(i,0,N-1) mk[i] = 0;
vector<vector<ld>> dist(N, vector<ld>(K+1,INF));
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]);
}
dfs(0,g,H);
priority_queue<z,vector<z>,greater<z>> pq;
dist[0][0] = 0;
pq.push({0,{0,0}});
rep(i,1,N-1) if(arr[i]==0 && mk[i]) {
pq.push({0,{i,0}});
dist[i][0] = 0;
}
vector<vector<bool>> vis(N, vector<bool>(K+1,0LL));
while (!pq.empty()) {
auto [d,h] = pq.top();pq.pop();
int u = h.first;
int ck = h.second;
if(vis[u][ck]) continue;
//cout << u << ' ' << d << ' ' << ck << '\n';
vis[u][ck] = 1;
for(auto &[v,w] : g[u]) {
rep(_,0,1) {
ld nd = d+w;
int cck = ck;
if (nd < dist[v][cck]) {
dist[v][cck] = nd;
pq.push({dist[v][cck],{v,cck}});
}
if(arr[v] == 2 && cck < K) {
cck++;
nd/=2;
}
}
}
}
if(!mk[H]) return -1;
ld ans = INF;
rep(i,0,K) 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... |