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 ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
double solve(int n, int m, int k, int h, vector<int> u, vector<int> v, vector<int> w, vector<int> a){
vector<pii> adj[n];
for(int i = 0; i < m; ++i){
adj[u[i]].pb({v[i], w[i]});
adj[v[i]].pb({u[i], w[i]});
}
queue<int> q;
vector<bool> vis0(n);
q.push(0);
vis0[0] = 1;
while(!q.empty()){
int x = q.front();
q.pop();
if(x == h)
continue;
for(auto [i, w] : adj[x])
if(!vis0[i]){
q.push(i);
vis0[i] = 1;
}
}
if(!vis0[h])
return -1;
k = min(k, (int)1e2);
vector<vector<double>> dis(n, vector<double>(k+1, 1e18));
priority_queue<pair<double, pii>> pq;
for(int i = 0; i < n; ++i){
if(i == 0 or (a[i] == 0 and vis0[i])){
dis[i][0] = 0;
pq.push({0,{i, 0}});
}
}
while(!pq.empty()){
double d = pq.top().ff; d = -d;
auto [x, y] = pq.top().ss; pq.pop();
if(d != dis[x][y]) continue;
if(x == h) continue;
for(auto [i, w] : adj[x]){
if(a[i] == 0) continue;
if(d+w < dis[i][y]){
dis[i][y] = d+w;
pq.push({-dis[i][y],{i, y}});
}
if(a[i] == 2 and y < k and (d+w)/2 < dis[i][y+1]){
dis[i][y+1] = (d+w)/2;
pq.push({-dis[i][y+1],{i, y+1}});
}
}
}
return *min_element(dis[h].begin(), dis[h].end());
}
// int main(){
// double kk = solve(3, 2, 30, 2,{1, 2},{2, 0},{12, 4},{1, 2, 1});
// double kk1 = solve(4, 4, 30, 3,{0, 0, 1, 2},{1, 2, 3, 3},{5, 4, 2, 4},{1, 0, 2, 1});
// return 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... |