이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "cyberland.h"
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
//g++ cyberland.cpp cyberland.h stub.cpp
const int N = 1e5 + 69;
const long long inf = 1e18;
vector<pair<int, int>> g[N];
double dis[N][33];
int vis[N];
void dfs(int v) {
if (vis[v])
return;
vis[v] = 1;
for (auto u : g[v])
dfs(u.f);
}
double solve(int n, int m, int k, int s, vector<int> x, vector<int> y, vector<int> c, vector<int> a) {
//reset
for (int i = 0;i < n;i++) {
g[i].clear();
vis[i] = 0;
}
for (int i = 0;i < m;i++) {
g[x[i]].push_back({y[i], c[i]});
g[y[i]].push_back({x[i], c[i]});
}
dfs(0);
if (!vis[s])
return -1;
for (int i = 0;i < n;i++) {
for (int j = 0;j <= k;j++)
dis[i][j] = inf;
}
dis[s][0] = 0;
priority_queue<tuple<double, int, int>> pq;
pq.push({0, 0, 0});
for (int i = 1;i < n;i++) {
if (a[i] == 0) {
dis[i][0] = 0;
pq.push({0, i, 0});
}
}
while (!pq.empty()) {
auto x = pq.top();
pq.pop();
int v, j;
double d;
tie(d, v, j) = x;
d = abs(d);
for (auto u : g[v]) {
if (a[u.f] == 0)
continue;
if (dis[u.f][j] < d + u.s) {
dis[u.f][j] = d + u.s;
pq.push({-dis[u.f][j], u.f, j});
}
if (a[v] == 2) {
if (j < k && dis[u.f][j + 1] < (d + u.s) / 2) {
dis[u.f][j] = (d + u.s) / 2;
pq.push({-dis[u.f][j + 1], u.f, j + 1});
}
}
}
}
double ans = inf;
for (int i = 0;i <= k;i++)
ans = min(ans, dis[s][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... |