#include "cyberland.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll oo = 1e18;
const int MAX = 1e5 + 5;
struct edge{
int u, c;
};
int n, k, f;
int A[MAX];
vector<edge> g[MAX];
bool visited[MAX];
vector<int> starts;
void dfs(int node){
visited[node] = 1;
for(auto& e:g[node]){
if(visited[e.u]) continue;
dfs(e.u);
}
}
double dist[MAX][32];
bool comp(int a, int b){
return dist[a % n][a / n] <= dist[b % n][b / n];
}
void dijkstra(){
set<int, decltype(&comp)> st(&comp);
for (int i = 0; i < n; i++)
{
for (int j = 0; j <= k; j++)
{
dist[i][j] = oo;
}
}
for(int a:starts){
dist[a][k] = 0;
st.insert(a + k * n);
}
while(!st.empty()){
int idx = *st.begin();
st.erase(st.begin());
int node = idx % n;
int l = idx / n;
double d = dist[node][l];
for(auto& e:g[node]){
double b = d + e.c;
if(b < dist[e.u][l]){
idx = e.u + l * n;
st.erase(idx);
dist[e.u][l] = b;
st.insert(idx);
}
if(l == 0 || A[e.u] != 2) continue;
if(b / 2 < dist[e.u][l - 1]){
idx = e.u + (l - 1) * n;
st.erase(idx);
dist[e.u][l - 1] = b / 2;
st.insert(idx);
}
}
}
}
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
n = N;
k = K;
f = H;
starts.clear();
for (int i = 0; i < n; i++)
{
A[i] = arr[i];
g[i].clear();
visited[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]});
}
g[f].clear();
dfs(0);
starts.push_back(0);
for (int i = 0; i < n; i++)
{
if(visited[i] && A[i] == 0){
starts.push_back(i);
}
}
dijkstra();
double ans = oo;
for(int i = 0; i <= k; ++i){
ans = min(ans, dist[f][i]);
}
if(ans == oo){
return -1;
}
else{
return ans;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
2804 KB |
Correct. |
2 |
Correct |
30 ms |
2768 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
3080 KB |
Correct. |
2 |
Correct |
32 ms |
3052 KB |
Correct. |
3 |
Correct |
30 ms |
3028 KB |
Correct. |
4 |
Correct |
31 ms |
3052 KB |
Correct. |
5 |
Correct |
31 ms |
3040 KB |
Correct. |
6 |
Correct |
30 ms |
5872 KB |
Correct. |
7 |
Correct |
40 ms |
5824 KB |
Correct. |
8 |
Correct |
27 ms |
8996 KB |
Correct. |
9 |
Correct |
26 ms |
2752 KB |
Correct. |
10 |
Correct |
26 ms |
2756 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
3012 KB |
Correct. |
2 |
Correct |
34 ms |
3068 KB |
Correct. |
3 |
Correct |
31 ms |
3028 KB |
Correct. |
4 |
Correct |
28 ms |
2644 KB |
Correct. |
5 |
Correct |
28 ms |
2764 KB |
Correct. |
6 |
Correct |
9 ms |
5460 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
780 ms |
28692 KB |
Correct. |
2 |
Correct |
953 ms |
3456 KB |
Correct. |
3 |
Correct |
835 ms |
3560 KB |
Correct. |
4 |
Correct |
876 ms |
3524 KB |
Correct. |
5 |
Correct |
653 ms |
2860 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
3028 KB |
Correct. |
2 |
Correct |
31 ms |
3096 KB |
Correct. |
3 |
Correct |
26 ms |
3056 KB |
Correct. |
4 |
Correct |
29 ms |
5972 KB |
Correct. |
5 |
Correct |
20 ms |
2644 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
3028 KB |
Correct. |
2 |
Correct |
26 ms |
3096 KB |
Correct. |
3 |
Correct |
51 ms |
27052 KB |
Correct. |
4 |
Correct |
21 ms |
5256 KB |
Correct. |
5 |
Correct |
23 ms |
2644 KB |
Correct. |
6 |
Correct |
25 ms |
3152 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
924 ms |
4252 KB |
Correct. |
2 |
Correct |
145 ms |
5172 KB |
Correct. |
3 |
Correct |
2114 ms |
37492 KB |
Correct. |
4 |
Correct |
1811 ms |
10732 KB |
Correct. |
5 |
Execution timed out |
3082 ms |
91632 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3045 ms |
18292 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |