#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plx pair<ll,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
using namespace std;
const int mxn=1e5+5;
vector<pair<int,int>>g[mxn];
double d[67][mxn]{0};
int pr[mxn]{0};
int get(int r){
return pr[r]==r?r:pr[r]=get(pr[r]);
}
priority_queue<pair<double,pii>,vector<pair<double,pii>>,greater<pair<double,pii>>>q;
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){
iota(pr,pr+N,0);
K=min(K,66);for(int i=0;i<M;i++){
g[x[i]].pb({y[i],i}),g[y[i]].pb({x[i],i});
if(x[i]==H||y[i]==H)continue;
pr[get(x[i])]=get(y[i]);
}
for(int i=0;i<=K;i++)for(int j=0;j<N;j++)d[i][j]=1e17;
d[0][0]=0;q.push({0,{0,0}});arr[0]=0;double ans=1e17;
for(int i=1;i<N;i++)if(arr[i]==0&&get(i)==get(0))d[0][i]=0,q.push({0,{0,i}});
while(!q.empty()){
auto u=q.top();q.pop();
if(d[u.s.f][u.s.s]<u.f)continue;
if(u.s.s==H){ans=min(ans,u.f);continue;}
for(auto v:g[u.s.s]){
if(!arr[v.f])continue;
if(d[u.s.f][v.f]>u.f+v.s)d[u.s.f][v.f]=u.f+v.s,q.push({u.f+v.s,{u.s.f,v.f}});
if(arr[v.f]==2&&u.s.f<K){
double t = (u.f+v.s)/2.0;
if(d[u.s.f+1][v.f]>t)d[u.s.f+1][v.f]=t,q.push({t,{u.s.f+1,v.f}});
}
}
}for(int i=0;i<N;i++)g[i].clear();
return (ans>=1e17?-1:ans);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
16 ms |
8540 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
8540 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
20 ms |
10584 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
75 ms |
25048 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
20 ms |
10840 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
18 ms |
8796 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
199 ms |
9208 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
666 ms |
13180 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |