#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
vector<bool> reach;
void dfs(int x , vector<vector<pair<long long ,long long>>> &adj)
{
if(reach[x])
return ;
reach[x] = 1;
for(auto u : adj[x])
dfs(u.first , adj);
}
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)
{
reach.assign(N , 0);
vector<vector<pair<long long ,long long>>> adj(N);
for(long long i = 0 ; i < M ; i++)
{
adj[x[i]].push_back({y[i] , c[i]});
adj[y[i]].push_back({x[i] , c[i]});
}
priority_queue<pair<double , long long> , vector<pair<double , long long>> , greater<pair<double , long long>>> pq;
vector<double> dist(N , 1e16);
vector<bool> vis(N , 0);
dist[0] = 0;
dfs(0 , adj);
pq.push({0 , 0});
for(int i = 0 ; i < N ; i++)
{
if(arr[i] == 0 && reach[i])
{
dist[i] = 0;
pq.push({0 , i});
}
}
while(!pq.empty())
{
auto tp = pq.top();
pq.pop();
double d = tp.first ;
long long node = tp.second;
if(vis[node])
continue;
vis[node] = 1;
for(auto [u , cost] : adj[node])
{
double nd = d + (double)cost;
if(nd < eps + dist[u])
{
dist[u] = nd;
pq.push({nd , u});
}
}
}
double mn = dist[H];
return (mn + eps >= 1e16 ? -1 : mn);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
600 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
632 KB |
Correct. |
2 |
Correct |
19 ms |
600 KB |
Correct. |
3 |
Correct |
19 ms |
600 KB |
Correct. |
4 |
Correct |
19 ms |
596 KB |
Correct. |
5 |
Correct |
22 ms |
592 KB |
Correct. |
6 |
Correct |
17 ms |
1440 KB |
Correct. |
7 |
Correct |
28 ms |
1456 KB |
Correct. |
8 |
Correct |
10 ms |
2652 KB |
Correct. |
9 |
Correct |
18 ms |
512 KB |
Correct. |
10 |
Correct |
17 ms |
344 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
22 ms |
604 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
29 ms |
9180 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
604 KB |
Correct. |
2 |
Correct |
24 ms |
604 KB |
Correct. |
3 |
Correct |
18 ms |
604 KB |
Correct. |
4 |
Correct |
18 ms |
1372 KB |
Correct. |
5 |
Correct |
16 ms |
348 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
600 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
604 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
600 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |