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>
#include "cyberland.h"
#define pii pair<int, int>
#define pb push_back
#define all(x) x.begin(), x.end()
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef long long ll;
const int MAXN = (int)1e6 + 7;
const int K = 70;
const int MOD = 998244353;
const double INF = (double)1e18 + 7;
int n, m, k, h, tmp, tmp2, tmp3, tmp4, ans, u, v, w;
int arr[MAXN];
double dp[MAXN][K];
bool seen[MAXN], sn[MAXN][K];
vector<pii> adj[MAXN];
vector<int> source;
priority_queue<pair<double, pii>, vector<pair<double, pii> >, greater<pair<double, pii> > > pq;
void DFS(int v) {
seen[v] = 1;
if (v == 0 || arr[v] == 0) source.pb(v);
for (auto cur:adj[v]) {
int u = cur.F, w = cur.S;
if (!seen[u]) DFS(u);
}
}
double solve(int N, int M, int kk, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> A) {
n = N; m = M; k = min(K-1, kk); h = H;
for (int i=0; i<n; i++) adj[i].clear();
source.clear();
fill(seen, seen+n+1, 0);
for (int j=0; j<K; j++) for (int i=0; i<n; i++) dp[i][j] = INF, sn[i][j] = 0;
for (int i=0; i<m; i++) {
u = x[i]; v = y[i]; w = c[i];
adj[u].pb(mp(v, w));
adj[v].pb(mp(u, w));
}
for (int i=0; i<n; i++) arr[i] = A[i];
seen[h] = 1;
DFS(0);
for (int s:source) {
dp[s][0] = 0;
pq.push(mp(0, mp(s, 0)));
}
while (pq.size()) {
auto cur = pq.top().S; pq.pop();
v = cur.F;
tmp = cur.S;
// if (sn[v][tmp]) continue;
// sn[v][tmp] = 1;
if (v == h) continue;
for (auto cur:adj[v]) {
int u = cur.F, w = cur.S;
if (dp[u][tmp] > dp[v][tmp]+w) {
// cout << "@" << v << " " << tmp << " " << u << " : " << dp[v][tmp]+w << endl;
dp[u][tmp] = dp[v][tmp]+w;
pq.push(mp(dp[u][tmp], mp(u, tmp)));
}
if (arr[u] == 2 && tmp+1 <= k && dp[u][tmp+1] > (dp[v][tmp]+w)/2.0) {
dp[u][tmp+1] = (dp[v][tmp]+w)/2.0;
// cout << "@" << v << " " << tmp << " " << u << " : " << dp[u][tmp+1] << endl;
pq.push(mp(dp[u][tmp+1], mp(u, tmp+1)));
}
}
}
double res = INF;
for (int i=0; i<=k; i++) res = min(res, dp[h][i]);
return (res == INF? -1 : res);
}
Compilation message (stderr)
cyberland.cpp: In function 'void DFS(int)':
cyberland.cpp:38:24: warning: unused variable 'w' [-Wunused-variable]
38 | int u = cur.F, w = cur.S;
| ^
# | 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... |