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"
using namespace std;
typedef double dbl;
typedef long long i64;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define ff first
#define ss second
#define MP make_pair
const int mxk = 32;
const int mxn = 1e5 + 10;
vector<pii> adj[mxn];
dbl dis[mxk][mxn];
bool in[mxn];
template<typename T> void ono_min(T &MIN, T CMP) { if(MIN > CMP) MIN = CMP; }
template<typename T> void ono_max(T &MAX, T CMP) { if(MAX < CMP) MAX = CMP; }
dbl solve(int N, int M, int K, int H, vi x, vi y, vi c, vi arr) {
for(int i = 0; i < N; i++) {
in[i] = 0;
adj[i].clear();
}
for(int i = 0; i < M; i++) {
adj[x[i]].push_back(MP(y[i], c[i]));
adj[y[i]].push_back(MP(x[i], c[i]));
}
// for(int i = 0; i < N; i++) {
// cout << i << ":\n";
// for(pii p : adj[i])
// cout << p.ff << ' ' << p.ss << endl;
// }
priority_queue<pair<dbl, int>> pq[mxk];
queue<int> q;
in[0] = 1;
q.push(0);
for(int i = 0; i < mxk; i++)
for(int j = 0; j < N; j++)
dis[i][j] = 1e18;
pq[0].push(MP(0.0, 0));
dis[0][0] = 0.0;
while(q.size()) {
int u = q.front();
q.pop();
if(arr[u] == 0) {
pq[0].push(MP(0.0, u));
dis[0][u] = 0.0;
}
for(pii p : adj[u]) {
int v = p.ff;
if(!in[v]) {
in[v] = 1;
q.push(v);
}
}
}
dbl ans = 1e18;
for(int i = 0; i < mxk && i <= K; i++) {
bool vis[N];
memset(vis, 0, sizeof vis);
while(pq[i].size()) {
dbl d = -pq[i].top().ff;
int u = pq[i].top().ss;
pq[i].pop();
if(vis[u]) continue;
// if(dis[i][u] < d) exit(1);
// ono_min(dis[i][u], d);
// cout << u << ' ' << i << ": " << dis[i][u] << ' ' << d << endl;
dis[i][u] = d;
vis[u] = 1;
if(u == H) continue;
for(pii p : adj[u]) {
int v = p.ff;
int c = p.ss;
if(v == 0 || arr[v] == 0) continue;
if(!vis[v]) {
pq[i].push(MP(-(d + c), v));
// ono_min(dis[i][v], dis[i][u] + c);
}
if(arr[v] == 2) {
pq[i].push(MP(-(d + c) / 2.0, v));
// ono_min(dis[i + 1][v], (dis[i][u] + c) / 2.0);
}
}
}
ono_min(ans, dis[i][H]);
}
return (ans < 1e18 ? ans : -1.0);
}
# | 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... |