This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(vr) vr.begin(), vr.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
struct vertex {
int v, d;
double dist;
bool operator < (const vertex &obj) const {
return mp(dist, v) > mp(obj.dist, obj.v);
}
};
const int N = 1e5 + 10;
vector<pii> G[N];
int vis[N];
double dist[N][40];
void dfs(int u, vi& vt, int del) {
vis[u] = 1;
vt.eb(u);
for (pii pa : G[u])
if (!vis[pa.fi] && pa.fi != del) dfs(pa.fi, vt, del);
}
double solve(int n, int m, int k, int h, vi x, vi y, vi c, vi arr) {
for (int i = 0; i < n; ++i) G[i].clear();
for (int i = 0; i < m; ++i) {
int u = x[i], v = y[i], w = c[i];
G[u].eb(v, w);
G[v].eb(u, w);
}
for (int i = 0; i < n; ++i) vis[i] = 0;
vi vt;
dfs(0, vt, h);
priority_queue<vertex> q;
for (int i = 0; i < n; ++i)
for (int j = 0; j <= k; ++j) dist[i][j] = 1e18;
dist[0][0] = 0;
q.push({0, 0, 0});
for (int x : vt)
if (!arr[x]) dist[x][0] = 0, q.push({x, 0, 0});
while (!q.empty()) {
int u = q.top().v, d = q.top().d;
double w = q.top().dist;
q.pop();
if (w != dist[u][d] || u == h) continue;
for (pii pa : G[u]) {
if (dist[u][d] + pa.se < dist[pa.fi][d]) {
dist[pa.fi][d] = dist[u][d] + pa.se;
q.push({pa.fi, d, dist[pa.fi][d]});
}
if (arr[u] == 2 && d < k && dist[u][d] / 2 + pa.se < dist[pa.fi][d + 1]) {
dist[pa.fi][d + 1] = dist[u][d] / 2 + pa.se;
q.push({pa.fi, d + 1, dist[pa.fi][d + 1]});
}
}
}
double res = 1e18;
for (int i = 0; i <= k; ++i) res = min(res, dist[h][i]);
return res;
}
# | 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... |