이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define all(v) ((v).begin(),(v).end())
#define F first
#define S second
typedef long long ll;
#define pii pair<ll,double>
using namespace std;
const ll mod = 1e9 + 7;
const ll mxN = 4e6 + 5;
struct path{
ll i,k;
double val;
};
bool operator<(path a,path b){
return a.val < b.val;
}
bool operator>(path a,path b){
return a.val > b.val;
}
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
vector<vector<pii>>v;
const int nsz = N + 3;
const int ksz = K + 3;
double dp[nsz][ksz];
v.resize(N + 3);
for(int i = 0;i < M;i++){
v[x[i]].push_back({y[i],(double)c[i]});
v[y[i]].push_back({x[i],(double)c[i]});
}
// cout<<nsz<<'\n';
for(int i = 0;i < N;i++){
if(arr[i] == 0) {
v[i].push_back({0,(double)0});
v[0].push_back({i,(double)0});
}
}
for(int i = 0;i < N;i++){
for(int j = 0;j <= K;j++){
dp[i][j] = 1e18;
}
}
dp[H][0] = 0;
priority_queue<path,vector<path>,greater<path>>q;
q.push({H,0,0});
while(q.size()){
auto u = q.top();
// cout<<u.i<<' '<<u.k<<' '<<u.val<<'\n';
q.pop();
if(dp[u.i][u.k] < u.val) continue;
for(auto x : v[u.i]){
if(arr[u.i] == 2 && u.k < K){
if(dp[x.F][u.k + 1] > u.val + (x.S / (exp2(u.k + 1)))){
dp[x.F][u.k + 1] = u.val + (x.S / (exp2(u.k + 1)));
q.push({x.F,u.k + 1,dp[x.F][u.k + 1]});
}
}
if(dp[x.F][u.k] > u.val + (x.S / (exp2(u.k)))){
dp[x.F][u.k] = u.val + (x.S / (exp2(u.k)));
q.push({x.F,u.k,dp[x.F][u.k]});
}
}
}
double ans = 1e18;
for(int i = 0; i <= K;i++){
ans = min(ans,dp[0][i]);
}
return ans;
}
// int main() {
// int T;
// assert(1 == scanf("%d", &T));
// while (T--){
// int N,M,K,H;
// assert(4 == scanf("%d %d %d\n%d", &N, &M, &K, &H));
// vector<int> x(M);
// vector<int> y(M);
// vector<int> c(M);
// vector<int> arr(N);
// for (int i=0;i<N;i++)
// assert(1 == scanf("%d", &arr[i]));
// for (int i=0;i<M;i++)
// assert(3 == scanf("%d %d %d", &x[i], &y[i], &c[i]));
// printf("%.12lf\n", solve(N, M, K, H, x, y, c, arr));
// }
// }
# | 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... |