이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
const ll INF = 1e16;
vll v; vector<vector<pair<ll, ll>>>g;
ll h,n;
void dfs(ll x) {
if (v[x]++) return;
if ((int)x%(int)n==h) return;
for (auto i : g[x]) {
dfs(i.first);
}
}
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) {
ll m = M, k = min(K, 32) + 1; h = H, n = N;
v = vll(n*k); g=vector<vector<pair<ll, ll>>>(n*k);
for (ll j = 0; j < k; j++) {
for (ll i = 0; i < m; i++) {
g[x[i] + j * n].push_back({ y[i] + j * n, c[i]*1.0/(1<<(int)j)});
g[y[i] + j * n].push_back({ x[i] + j * n, c[i]*1.0/ (1 << (int)j)});
if (j && arr[x[i]] == 2) {
g[x[i] + j * n].push_back({ y[i] + (j-1) * n, c[i] * 1.0 / (1 << (int)j) });
}
if (j && arr[y[i]] == 2) {
g[y[i] + j * n].push_back({ x[i] + (j - 1) * n, c[i] * 1.0 / (1 << (int)j) });
}
}
}
for (ll i = 0; i < k; i++) {
dfs(i*n);
}
vll save = v;
v = vll(n * k, INF);
priority_queue<pair<ll,ll>, std::vector<pair<ll,ll>>, std::greater<pair<ll,ll>>> q;
q.push({ 0,0 }); v[0] = 0;
for (ll j = 0; j < k; j++) {
for (ll i = 0; i < n; i++) {
if (arr[i] == 0&&save[i+j*n]) {
q.push({ 0, i + j * n });
v[i + j * n] = 0;
}
}
}
while (q.size()) {
pair<ll, ll> he = q.top(); q.pop();
if (v[he.second] < he.first||(int)he.second%(int)n==h) {
continue;
}
for (auto i : g[he.second]) {
if (v[i.first] <= he.first + i.second) {
continue;
}
v[i.first] = he.first + i.second;
q.push({ v[i.first],i.first });
}
}
return v[h];
}
# | 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... |