#include <bits/stdc++.h>
using namespace std;
using ll = long long; using pii = pair<ll,ll>;
using ld = long double; using vi = vector<int>;
const ld INF = 1e18;
double solve(int N, int M, int K, int H, vi x, vi y, vi c, vi arr) {
ld tmin[N][K+1];
bool dfsf[N];
for (ll i=0;i<N;i++) {
dfsf[i]=0;
for (ll k=0;k<=K;k++) {
tmin[i][k]=INF;
}
}
vector<pii> adj[N]; //vertex,cost
for (ll i=0;i<M;i++) {
adj[x[i]].push_back({y[i],c[i]});
adj[y[i]].push_back({x[i],c[i]});
}
stack<int> s;
s.push(0);
while (!s.empty()) {
ll x0 = s.top(); s.pop();
if (!dfsf[x0]) {
dfsf[x0]=1;
if (x0==H) {
continue;
}
for (pii p0: adj[x0]) {
s.push(p0.first);
}
}
}
if (!dfsf[H]) {
return -1.0;
}
priority_queue<pair<ll,pair<ld,ll>>> pq; //{#k,{time,position}}
pq.push({0,{0.0,0}});
for (ll i=0;i<N;i++) {
if (dfsf[i] && (arr[i]==0)) {
pq.push({0,{0.0,i}});
}
}
while (!pq.empty()) {
auto A = pq.top(); pq.pop();
ld T = A.second.first; ll x0 = A.second.second; ll k = A.first;
if (arr[x0]==0 && T != 0.0) {
continue;
}
if (tmin[x0][k]<=(T+1e-10)) {
continue;
}
tmin[x0][k]=min(tmin[x0][k],T);
if (x0==H) {
continue;
}
for (pii p0: adj[x0]) {
ll y0 = p0.first; ld ce = p0.second;
pq.push({k,{ce+T,y0}});
if (arr[x0]==2 && k<K) {
pq.push({k+1,{ce+T/2,y0}});
}
}
}
ld ans = INF;
for (ll k=0;k<=K;k++) {
ans = min(ans,tmin[H][k]);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
860 KB |
Correct. |
2 |
Correct |
26 ms |
856 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
1872 KB |
Correct. |
2 |
Correct |
41 ms |
2132 KB |
Correct. |
3 |
Correct |
36 ms |
1872 KB |
Correct. |
4 |
Correct |
35 ms |
1944 KB |
Correct. |
5 |
Correct |
37 ms |
2048 KB |
Correct. |
6 |
Correct |
34 ms |
7008 KB |
Correct. |
7 |
Correct |
40 ms |
7244 KB |
Correct. |
8 |
Correct |
20 ms |
12376 KB |
Correct. |
9 |
Correct |
31 ms |
1284 KB |
Correct. |
10 |
Correct |
30 ms |
1428 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
1912 KB |
Correct. |
2 |
Correct |
52 ms |
1876 KB |
Correct. |
3 |
Correct |
48 ms |
1996 KB |
Correct. |
4 |
Correct |
43 ms |
1368 KB |
Correct. |
5 |
Correct |
43 ms |
1360 KB |
Correct. |
6 |
Correct |
13 ms |
5656 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3060 ms |
36652 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1309 ms |
1888 KB |
Correct. |
2 |
Correct |
2093 ms |
2248 KB |
Correct. |
3 |
Correct |
2115 ms |
2116 KB |
Correct. |
4 |
Execution timed out |
3028 ms |
4972 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
177 ms |
2128 KB |
Correct. |
2 |
Correct |
205 ms |
1952 KB |
Correct. |
3 |
Correct |
62 ms |
47184 KB |
Correct. |
4 |
Correct |
777 ms |
5564 KB |
Correct. |
5 |
Correct |
50 ms |
1364 KB |
Correct. |
6 |
Correct |
183 ms |
2128 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3027 ms |
1264 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
968 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |