이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define inf 1e18
#define dinf 1e9
using namespace std;
vector<array<ll, 2>> adj[100000];
ll h;
bool visited[100000];
priority_queue<array<ll, 2>, vector<array<ll, 2>>, greater<array<ll, 2>>> pq[60];
ll dp[100000][61], ep = dinf;
void dfs(ll u)
{
visited[u] = 1;
for (auto [v, x] : adj[u])
{
if (v != h && !visited[v])
{
dfs(v);
}
}
}
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)
{
K = min(K, 60), h = H;
for (int i = 0; i < N; ++i)
{
visited[i] = 0;
adj[i].clear();
for (int j = 0; j <= K; ++j)
{
dp[i][j] = 1e18;
}
}
for (int i = 0; i < M; ++i)
{
adj[x[i]].push_back({y[i], c[i]});
adj[y[i]].push_back({x[i], c[i]});
}
dfs(0);
for (int i = 0; i < N; ++i)
{
if (visited[i] && (!arr[i] || !i))
{
dp[i][K] = 0;
pq[K].push({0, (ll)i});
}
}
for (int i = K; i >= 0; --i)
{
while (!pq[i].empty())
{
auto [w, du] = pq[i].top();
pq[i].pop();
ll u = (ll)du;
if (dp[u][i] != w || u == H)
continue;
for (auto [v, x] : adj[u])
{
if (dp[v][i] - (w + (ll)x) > ep)
{
dp[v][i] = w + (ll)x;
pq[i].push({dp[v][i], (ll)v});
}
if (i && arr[v] == 2 && (dp[v][i - 1] - (ll)(w + (ll)x) / 2) > ep)
{
dp[v][i - 1] = (w + (ll)x) / 2;
pq[i - 1].push({dp[v][i - 1], (ll)v});
}
}
}
}
ll f = inf;
for (int i = 0; i <= K; ++i)
{
f = min(f, dp[H][i]);
}
return f;
}
# | 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... |