이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#include "cyberland.h"
struct dsu {
vector<int> par, sz;
int total_groups;
void init(int n) {
par.resize(n); sz.resize(n);
for (int i = 0; i < n; i++) {
par[i] = i;
sz[i] = 1;
}
}
int find(int x) {
if (par[x] == x) return x;
else return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y) return;
if (sz[x] < sz[y]) swap(x, y);
par[y] = x;
sz[x] += sz[y];
total_groups--;
}
bool same(int x, int y) {
x = find(x);
y = find(y);
if (x == y) return true;
else return false;
}
};
#define ld long double
double solve(int N, int M, int K, int H, vector<int> fir, vector<int> sec, vector<int> co, vector<int> arr) {
K = min(K, 69);
vector<vector<pair<int,int>>> g(N);
dsu ds; ds.init(N);
for (int i = 0; i < M; i++) {
if (fir[i] != H && sec[i] != H) ds.unite(fir[i], sec[i]);
g[fir[i]].push_back(make_pair(co[i], sec[i]));
g[sec[i]].push_back(make_pair(co[i], fir[i]));
}
vector<ld> pwr(K + 1, 1);
for (int i = 1; i <= K; i++) {
pwr[i] = pwr[i - 1] / 2;
}
arr[0] = 0;
vector<vector<ld>> dist(K + 1, vector<ld>(N, 1e18));
using node = tuple<ld, int, int>;
priority_queue<node, vector<node>, greater<node>> pq;
auto enq = [&](int k, int x, ld d) {
if (dist[k][x] > d) {
dist[k][x] = d;
pq.push({ d,k,x });
}
};
enq(K, H, 0);
while (pq.size()) {
auto [d, k, x] = pq.top(); pq.pop();
if (dist[k][x] < d) continue;
if (arr[x] == 0) return (double)d;
for (auto& [c, v] : g[x]) {
if (ds.find(v) != ds.find(0)) continue;
enq(k, v, d + c * pwr[K - k]);
if (arr[x] == 2 && k > 0) enq(k - 1, v, d + c * pwr[K - k + 1]);
}
}
return (double)-1;
}
# | 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... |