이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "cyberland.h"
using namespace std;
#define ll long long
#define pb push_back
#define all(c) c.begin(), c.end()
#define endl "\n"
const double PI=3.141592653589;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "LINE(" << __LINE__ << ") -> " <<"[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
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> arr) {
vector<vector<pair<int,int>>>adj(n+1);
for(int i = 0;i<m;++i)adj[x[i]].pb({y[i],c[i]}),adj[y[i]].pb({x[i],c[i]});
priority_queue<vector<double>,vector<vector<double>>,greater<vector<double>>>pq;
vector<vector<double>>dist(n+1, vector<double>(k+1,1e18));
for(int j = 0;j<=k;++j)dist[0][j] = 0,pq.push({0,0,(double)j});
vector<vector<int>>visited(n+1, vector<int>(k+1));
while(!pq.empty()){
int u = pq.top()[1], j = pq.top()[2];
double dd = pq.top()[0];
pq.pop();
if(dd!=dist[u][j])continue;
if(u==h)continue;
for(auto &[v,c] : adj[u]){
double curr_dist = dist[v][j],new_dist = dist[u][j]+c;
if(arr[v]==1)new_dist = dist[u][j]+c;
else if(arr[v]==0)new_dist = 0;
else if(arr[v]==2){
if(j)new_dist = min(new_dist,(dist[u][j-1]+c)/2);
if(j+1 <= k){
double curr_dist = dist[v][j+1], new_dist = (dist[u][j]+c)/2;
if(new_dist < curr_dist){
dist[v][j+1] = new_dist;
pq.push({new_dist, (double)v,(double)(j+1)});
}
}
}
if(new_dist < curr_dist){
dist[v][j] = new_dist;
pq.push({new_dist,(double)v,(double)j});
}
}
}
double res = 1e18;
for(int i = 0;i<=k;++i)res = min(res, dist[h][i]);
if(res==1e18)res = -1;
return res;
}
# | 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... |