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 "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME (1.0 * clock() / CLOCKS_PER_SEC)
using vi = vector<int>;
using ar = pair<double,int>;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
typedef pair<double, int> ar;
const int N = 1e5 + 10;
const double oo = 1e10;
int n, m, h;
double ans = 0;
bool vis[N];
double dis[N], dis2[N];
vector<ii> adj[N];
priority_queue<ar, vector<ar>, greater<ar>> pq;
void dijkstra(){
fill(vis,vis+n+1,0);
for(int i = 0; i < n; i++)
if(dis[i]<oo) pq.push({dis[i],i});
while(!pq.empty()){
auto tmp = pq.top(); pq.pop();
double D=tmp.fi; int a=tmp.se;
if(vis[a] || a==h) continue; vis[a]=1;
for(auto tmp : adj[a]) {
int b=tmp.fi, w=tmp.se;
if(dis[b]>dis[a]+w)
dis[b]=dis[a]+w, pq.push({dis[b],b});
}
}
ans = min(ans, dis[h]);
}
double solve(int N, int M, int K, int H, vi x, vi y, vi c, vi A) {
n = N, m = M, h = H, K = min(K, 67);
fill(dis, dis + n, oo); ans = oo;
for (int i = 0; i < n; i++) adj[i].clear();
for (int i = 0; i < m; i++)
adj[x[i]].push_back({y[i], c[i]}),
adj[y[i]].push_back({x[i], c[i]});
dis[0] = 0; dijkstra(); if (dis[h] >= oo) return -1;
for (int i = 0; i < n; i++)
if (dis[i] != oo) dis[i] = A[i] && i ? oo : 0;
for (int i = 0; i <= K; i++) {
dijkstra(); fill(dis2, dis2 + n, oo);
for (int j = 0; j < n; j++)
if (A[j] > 1) for (auto tmp : adj[j]) {
int u=tmp.fi, w=tmp.se;
dis2[u] = min(dis2[u], dis[j] / 2 + w);
}
for (int j = 0; j < n; j++) dis[j] = dis2[j];
}
return ans;
}
Compilation message (stderr)
cyberland.cpp: In function 'void dijkstra()':
cyberland.cpp:39:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
39 | if(vis[a] || a==h) continue; vis[a]=1;
| ^~
cyberland.cpp:39:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
39 | if(vis[a] || a==h) continue; vis[a]=1;
| ^~~
cyberland.cpp:38:10: warning: unused variable 'D' [-Wunused-variable]
38 | double D=tmp.fi; int a=tmp.se;
| ^
# | 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... |