이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#include "cyberland.h"
const int maxn = 2e5 + 5;
const double INF = 1e18;
const double eps = 1e-9;
vector<pll> adj[maxn];
int vis[maxn], vis2[maxn];
double dist[maxn][81];
void dfs(int pos){
vis[pos] = 1;
for(auto [x, w] : adj[pos]){
if(vis[x]) continue;
dfs(x);
}
}
struct info{
double d;
int pos, l;
info(){}
info(double _d, int _pos, int _l) : d(_d), pos(_pos), l(_l){}
bool operator > (const info& other) const{
if(l != other.l) return l > other.l;
return d > other.d;
}
};
priority_queue<info, vector<info>, greater<info>> q;
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) {
k = min(k, 80);
for(int i = 0; i < n; i++) adj[i].clear(), vis[i] = vis2[i] = 0;
for(int i = 0; i < m; i++){
adj[x[i]].pb({y[i], c[i]});
adj[y[i]].pb({x[i], c[i]});
}
dfs(0);
if(!vis[h]) return -1;
for(int i = 1; i < n; i++) for(int j = 0; j <= k; j++) dist[i][j] = INF;
arr[0] = 0;
for(int i = 0; i < n; i++){
if(arr[i] == 0 && vis[i]){
// born.insert(i);
// dist[i][0] = 0;
// for(int j = 0; j <= k; j++) dist[i][j] = 0;
// q.push(info(0, i, 0));
}
}
q.push(info(0, 0, 0));
while(!q.empty()){
auto [d, pos, l] = q.top(); q.pop();
vis2[pos] = 1;
if(dist[pos][l] < d || pos == h) continue;
// if(arr[pos] == 0 && l > 0) continue;
if(arr[pos] == 0) dist[pos][l] = d = 0;
for(auto [x, w] : adj[pos]){
if(dist[x][l] > d + w){
dist[x][l] = d + w;
q.push(info(dist[x][l], x, l));
}
}
if(arr[pos] == 2 && l < k){
d /= 2, l++;
if(dist[pos][l] < d) continue;
for(auto [x, w] : adj[pos]){
if(dist[x][l] > d + w){
dist[x][l] = d + w;
q.push(info(dist[x][l], x, l));
}
}
}
}
// for(int i = 0; i < n; i++) assert(vis[i] == vis2[i]);
double ans = INF;
for(int i = 0; i <= k; i++) ans = min(ans, dist[h][i]);
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... |