이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
double solve(int n, int m, int k, int h, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> a) {
vector<vector<pair<int,long double>>> g(n);
for(int i = 0;i < m;i++){
g[x[i]].pb({y[i],c[i]});
g[y[i]].pb({x[i],c[i]});
}
set<tuple<long double,int,int>> q;
q.insert({0,0,k});
long double dis[n][k + 1];
for(int i = 0;i < n;i++){
for(int j = 0;j <= k;j++){
dis[i][j] = 1e18;
}
}
dis[0][k] = 0;
while(!q.empty()){
auto [cost,v,nk] = *q.begin();q.erase(*q.begin());
if(dis[v][nk] < cost) continue;
for(auto [to,w] : g[v]){
if(a[to] == 0){
if(dis[to][nk] > 0){
dis[to][nk] = 0;
q.insert({0,to,nk});
}
} else if(a[to] == 1){
if(dis[v][nk] + w < dis[to][nk]){
dis[to][nk] = dis[v][nk] + w;
q.insert({dis[to][nk],to,nk});
}
} else{
if(nk == 0){
if(dis[v][nk] + w < dis[to][nk]){
dis[to][nk] = dis[v][nk] + w;
q.insert({dis[to][nk],to,nk});
}
} else{
if((dis[v][nk] + w) / 2 < dis[to][nk]){
dis[to][nk] = (dis[v][nk] + w) / 2;
q.insert({dis[to][nk],to,nk});
}
}
}
}
}
long double ans = 1e18;
for(int i = 0;i <= k;i++){
ans = min(ans,dis[h][i]);
}
if(ans == 1e18) ans = -1;
return ans;
}
# | 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... |