#include "cyberland.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
#include <queue>
typedef long long llong;
const int MAXN = 100000 + 10;
const llong INF = 1e18;
const int INTINF = 1e9;
int n, m, k, h;
bool vis[MAXN];
llong dist[MAXN];
int ability[MAXN];
std::vector <std::pair <int,int>> g[MAXN];
std::priority_queue <std::pair <llong,int>> pq;
double toReach[MAXN];
void reset()
{
for (int i = 1 ; i <= n ; ++i)
{
g[i].clear();
dist[i] = ability[i] = 0;
toReach[i] = 0.0;
vis[i] = false;
}
while (!pq.empty())
{
pq.pop();
}
}
void dfs(int node)
{
vis[node] = true;
for (const auto &[u, e] : g[node])
{
if (vis[u])
{
continue;
}
dfs(u);
}
}
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)
{
n = N;
m = M;
k = K;
h = H + 1;
reset();
for (int i = 0 ; i < m ; ++i)
{
g[x[i] + 1].emplace_back(y[i] + 1, c[i]);
g[y[i] + 1].emplace_back(x[i] + 1, c[i]);
}
dfs(1);
if (!vis[h])
{
return -1;
}
for (int i = 2 ; i <= n ; ++i)
{
ability[i] = arr[i - 1];
}
std::fill(dist + 1, dist + 1 + n, INF);
for (int i = 1 ; i <= n ; ++i)
{
if (!vis[i]) continue;
if (ability[i] == 0)
{
dist[i] = 0;
pq.push({0, i});
}
}
std::fill(vis + 1, vis + 1 + n, false);
while (!pq.empty())
{
auto [currDist, node] = pq.top();
pq.pop();
if (vis[node])
{
continue;
}
vis[node] = true;
for (const auto &[u, e] : g[node])
{
if (dist[u] > dist[node] + e)
{
dist[u] = dist[node] + e;
pq.push({-dist[u], u});
}
}
}
for (int i = 1 ; i <= n ; ++i)
{
toReach[i] = dist[i];
if (ability[i] == 2)
{
int minEdge = INTINF;
for (const auto &[u, e] : g[i])
{
minEdge = std::min(minEdge, u);
}
toReach[i] /= 2.0;
if (k > 60)
{
toReach[i] = std::min(toReach[i], (double)minEdge);
break;
}
for (int j = 0 ; j < k && toReach[i] >= minEdge ; ++j)
{
toReach[i] += minEdge;
toReach[i] /= 2.0;
}
}
}
std::fill(vis + 1, vis + 1 + n, false);
std::fill(dist + 1, dist + 1 + n, INF);
pq.push({0, h});
dist[h] = 0;
while (!pq.empty())
{
auto [currDist, node] = pq.top();
pq.pop();
if (vis[node])
{
continue;
}
vis[node] = true;
for (const auto &[u, e] : g[node])
{
if (dist[u] > dist[node] + e)
{
dist[u] = dist[node] + e;
pq.push({-dist[u], u});
}
}
}
double ans = INF;
for (int i = 1 ; i <= n ; ++i)
{
ans = std::min(ans, (double)dist[i] + toReach[i]);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
2772 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
2832 KB |
Correct. |
2 |
Correct |
23 ms |
2760 KB |
Correct. |
3 |
Correct |
22 ms |
2796 KB |
Correct. |
4 |
Correct |
23 ms |
2772 KB |
Correct. |
5 |
Correct |
23 ms |
2792 KB |
Correct. |
6 |
Correct |
21 ms |
3540 KB |
Correct. |
7 |
Correct |
27 ms |
3552 KB |
Correct. |
8 |
Correct |
12 ms |
4508 KB |
Correct. |
9 |
Correct |
22 ms |
2736 KB |
Correct. |
10 |
Correct |
21 ms |
2740 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
23 ms |
2812 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
32 ms |
9236 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
2820 KB |
Correct. |
2 |
Correct |
21 ms |
2888 KB |
Correct. |
3 |
Correct |
20 ms |
2860 KB |
Correct. |
4 |
Correct |
22 ms |
3776 KB |
Correct. |
5 |
Correct |
17 ms |
2644 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
21 ms |
2888 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
2920 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
2864 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |