#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;
if (node == h)
{
return;
}
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)
{
reset();
n = N;
m = M;
k = K;
h = H + 1;
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;
if (node != h)
{
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])
{
if (u == h)
{
continue;
}
minEdge = std::min(minEdge, u);
}
if (k != 0) toReach[i] /= 2.0;
if (k > 60)
{
toReach[i] = std::min(toReach[i], (double)2*minEdge);
break;
}
for (int j = 1 ; j < k && toReach[i] >= 2*minEdge ; ++j)
{
toReach[i] /= 2.0;
toReach[i] += minEdge;
}
}
}
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
2772 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
2860 KB |
Correct. |
2 |
Correct |
23 ms |
2796 KB |
Correct. |
3 |
Correct |
22 ms |
2772 KB |
Correct. |
4 |
Correct |
24 ms |
2824 KB |
Correct. |
5 |
Correct |
23 ms |
2808 KB |
Correct. |
6 |
Correct |
25 ms |
3608 KB |
Correct. |
7 |
Correct |
27 ms |
3540 KB |
Correct. |
8 |
Correct |
13 ms |
4436 KB |
Correct. |
9 |
Correct |
21 ms |
2644 KB |
Correct. |
10 |
Correct |
21 ms |
2736 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
2796 KB |
Correct. |
2 |
Correct |
24 ms |
2840 KB |
Correct. |
3 |
Correct |
26 ms |
2880 KB |
Correct. |
4 |
Correct |
22 ms |
2740 KB |
Correct. |
5 |
Correct |
22 ms |
2744 KB |
Correct. |
6 |
Correct |
6 ms |
3412 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
25 ms |
8160 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
2908 KB |
Correct. |
2 |
Correct |
20 ms |
2772 KB |
Correct. |
3 |
Correct |
19 ms |
2900 KB |
Correct. |
4 |
Correct |
22 ms |
3748 KB |
Correct. |
5 |
Correct |
18 ms |
2724 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
2820 KB |
Correct. |
2 |
Correct |
17 ms |
2892 KB |
Correct. |
3 |
Correct |
32 ms |
7764 KB |
Correct. |
4 |
Correct |
14 ms |
3644 KB |
Correct. |
5 |
Correct |
21 ms |
2744 KB |
Correct. |
6 |
Correct |
19 ms |
2844 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
20 ms |
2776 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
22 ms |
2904 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |