이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) __VA_ARGS__;
#else
#define debug(...)
#endif
const double INF = 1e15;
debug(int tc = 0);
double solve(int N, int M, int K, int H, vector<int> x,
vector<int> y, vector<int> c, vector<int> arr) {
vector adj(N, vector<pair<int, int>>());
for(int i = 0; i < M; i++) {
if(x[i] != H) adj[x[i]].emplace_back(y[i], c[i]);
if(y[i] != H) adj[y[i]].emplace_back(x[i], c[i]);
}
debug({
tc++;
if(tc == 195) {
cerr << N << ' ' << M << ' ' << K << '\n';
cerr << H << '\n';
for(int i : arr) cerr << i << ' ';
cerr << '\n';
for(int i = 0; i < M; i++)
cerr << x[i] << ' ' << y[i] << ' ' << c[i] << '\n';
}
});
vector<int> mark(N, 0);
const auto connected = [&](const auto &self, int u, int target) -> bool {
if(u == target) return true;
mark[u] = 1;
for(auto [v, c] : adj[u]) if(!mark[v]) {
if(self(self, v, target)) return true;
}
return false;
};
if(!connected(connected, 0, H)) {
return -1.0;
}
const auto dijkstra = [&](const vector<int> &sources, vector<int> &vis,
vector<double> &dist) {
using state = pair<double, int>; // dist, node
fill(vis.begin(), vis.end(), 0);
priority_queue<state, vector<state>, greater<state>> pq;
for(int i : sources) pq.push({dist[i], i});
while(!pq.empty()) {
int u = pq.top().second; pq.pop();
if(vis[u]) continue;
vis[u] = 1;
for(auto [v, c] : adj[u]) {
if(dist[v] > dist[u] + c) {
pq.push({dist[v] = dist[u] + c, v});
}
}
}
};
vector<int> vis(N, 0);
vector<int> sources{0};
vector<double> dist(N, INF);
for(int i : sources)
dist[i] = 0.0;
dijkstra(sources, vis, dist);
for(int i = 1; i < N; i++) if(vis[i] && arr[i] == 0)
sources.push_back(i);
fill(dist.begin(), dist.end(), INF);
for(int i : sources)
dist[i] = 0.0;
vector<double> new_dist(N);
double ans = INF;
for(int it = 0; it <= min(K, 95); it++) {
// debug(cerr << "it = " << it << '\n');
if(it == 1) {
sources.clear();
for(int i = 0; i < N; i++) if(arr[i] != 1 && vis[i])
sources.push_back(i);
fill(mark.begin(), mark.end(), 0);
bool ok = 0;
for(int i : sources)
ok |= connected(connected, i, H);
if(!ok) break;
}
if(it > 0) {
for(int i = 0; i < N; i++) {
if(arr[i] == 0) new_dist[i] = 0.0;
else if(arr[i] == 1) new_dist[i] = INF;
else {
new_dist[i] = INF;
for(auto [v, c] : adj[i]) if(v != H)
new_dist[i] = min(new_dist[i], (dist[v] + c) / 2.0);
}
}
swap(dist, new_dist);
}
dijkstra(sources, vis, dist);
ans = min(ans, dist[H]);
// debug({
// for(int i = 0; i < N; i++) {
// cerr << "dist[" << i << "] = " << dist[i] << '\n';
// }
// });
}
debug({
if(tc == 195) cerr << ans << '\n';
});
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... |