이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "cyberland.h"
using namespace std;
typedef double dbl;
typedef long long i64;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define ff first
#define ss second
#define MP make_pair
const int mxk = 32;
const int mxn = 1e5 + 10;
vector<pii> adj[mxn];
dbl dis[mxk][mxn];
bool in[mxn];
template<typename T> void ono_min(T &MIN, T CMP) { if(MIN > CMP) MIN = CMP; }
template<typename T> void ono_max(T &MAX, T CMP) { if(MAX < CMP) MAX = CMP; }
dbl solve(int N, int M, int K, int H, vi x, vi y, vi c, vi arr) {
for(int i = 0; i < N; i++) {
in[i] = 0;
adj[i].clear();
}
for(int i = 0; i < M; i++) {
adj[x[i]].push_back(MP(y[i], c[i]));
adj[y[i]].push_back(MP(x[i], c[i]));
}
priority_queue<pair<dbl, int>> pq[mxk];
queue<int> q;
in[0] = 1;
q.push(0);
for(int i = 0; i < mxk; i++)
for(int j = 0; j < N; j++)
dis[i][j] = 1e18;
pq[0].push(MP(0.0, 0));
dis[0][0] = 0.0;
while(q.size()) {
int u = q.front();
q.pop();
if(arr[u] == 0) {
pq[0].push(MP(0.0, u));
dis[0][u] = 0.0;
}
for(pii p : adj[u]) {
int v = p.ff;
if(!in[v]) {
in[v] = 1;
q.push(v);
}
}
}
dbl ans = 1e18;
for(int i = 0; i < mxk && i <= K; i++) {
bool vis[N];
memset(vis, 0, sizeof vis);
while(pq[i].size()) {
dbl d = -pq[i].top().ff;
int u = pq[i].top().ss;
pq[i].pop();
if(vis[u]) continue;
vis[u] = 1;
if(u == H) continue;
for(pii p : adj[u]) {
int v = p.ff;
int c = p.ss;
if(v == 0 || arr[v] == 0) continue;
if(!vis[v]) {
pq[i].push(MP(-(d + c), v));
ono_min(dis[i][v], dis[i][u] + c);
}
if(arr[v] == 1) {
pq[i].push(MP(-(d + c) / 2.0, v));
ono_min(dis[i + 1][v], (dis[i][u] + c) / 2.0);
}
}
}
ono_min(ans, dis[i][H]);
}
return (ans < 1e18 ? ans : -1.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... |