#include "cyberland.h"
#include<bits/stdc++.h>
using namespace std;
using db=double;
using pii=pair<int,int>;
using ll=long long;
#define eb emplace_back
#define f first
#define s second
const db eps=1e-14;
using A=pair<int,db>;
using B=pair<A,int>;
struct cmp{
bool operator()(const B &l,const B &r)const{
if(l.f.f!=r.f.f) return l.f.f>r.f.f;
return l.f.s-r.f.s > eps;
}
};
vector<pii> adj[100005];
A d[100005];
priority_queue<B,vector<B>,cmp> pq;
queue<int> q;
bitset<100005> vis;
double solve(int N, int M, int K, int H, std::vector<int> U, std::vector<int> V, std::vector<int> W, std::vector<int> arr) {
for(int i=0;i<N;++i) adj[i].clear();
for(int i=0;i<M;++i) adj[U[i]].eb(V[i],W[i]), adj[V[i]].eb(U[i],W[i]);
q.emplace(0);
vis.reset();
vis[0]=1;
while(!q.empty()){
int u=q.front(); q.pop();
if(u==H) continue;
for(auto &[v,w]:adj[u]){
if(!vis[v]) vis[v]=1, q.emplace(v);
}
}
if(!vis[H]) return -1;
function<void(db)> dijk=[&](db lim){
while(!pq.empty()) pq.pop();
pq.emplace(A(0,0),0);
d[0]={0,0};
for(int i=1;i<N;++i){
if(vis[i]&&arr[i]==0) pq.emplace(A(0,0),i), d[i]={0,0};
else d[i]={1e9,0};
}
while(!pq.empty()){
auto [w,u]=pq.top(); pq.pop();
if(u==H) continue;
for(auto &[v,vw]:adj[u]){
A w2={w.f,w.s+vw};
if(arr[v]==2 && w2.s-lim>eps) ++w2.f, w2.s/=2;
if(d[v].f>w2.f || d[v].f==w2.f&&d[v].s-w2.s>eps){
d[v]=w2;
pq.emplace(w2,v);
}
}
}
};
db l=0,r=1e14;
while(r-l>eps){
db mid=(l+r)/2;
dijk(mid);
if(d[H].f>=K) l=mid;
else r=mid;
}
dijk(l);
return d[H].s;
}
Compilation message
cyberland.cpp: In lambda function:
cyberland.cpp:57:47: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
57 | if(d[v].f>w2.f || d[v].f==w2.f&&d[v].s-w2.s>eps){
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
39 ms |
4188 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
241 ms |
4188 KB |
Correct. |
2 |
Correct |
303 ms |
4604 KB |
Correct. |
3 |
Correct |
283 ms |
4356 KB |
Correct. |
4 |
Correct |
312 ms |
4432 KB |
Correct. |
5 |
Correct |
296 ms |
4188 KB |
Correct. |
6 |
Correct |
471 ms |
4908 KB |
Correct. |
7 |
Correct |
623 ms |
4900 KB |
Correct. |
8 |
Correct |
272 ms |
5848 KB |
Correct. |
9 |
Correct |
146 ms |
4248 KB |
Correct. |
10 |
Correct |
149 ms |
4432 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
398 ms |
4296 KB |
Correct. |
2 |
Correct |
397 ms |
4552 KB |
Correct. |
3 |
Correct |
348 ms |
4392 KB |
Correct. |
4 |
Correct |
184 ms |
4500 KB |
Correct. |
5 |
Correct |
180 ms |
4256 KB |
Correct. |
6 |
Correct |
114 ms |
4952 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
245 ms |
8280 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
138 ms |
4360 KB |
Correct. |
2 |
Correct |
152 ms |
4188 KB |
Correct. |
3 |
Correct |
174 ms |
4436 KB |
Correct. |
4 |
Correct |
346 ms |
5200 KB |
Correct. |
5 |
Correct |
73 ms |
4184 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
183 ms |
4424 KB |
Correct. |
2 |
Correct |
126 ms |
4432 KB |
Correct. |
3 |
Correct |
31 ms |
9304 KB |
Correct. |
4 |
Correct |
187 ms |
5140 KB |
Correct. |
5 |
Correct |
88 ms |
4256 KB |
Correct. |
6 |
Correct |
165 ms |
4372 KB |
Correct. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
202 ms |
4396 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
196 ms |
4440 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |