#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n;int m;int KK;int HH;
int ar[200005];
int xar[200005];int yar[200005];int car[200005];
vector<pair<int,int>>e[200005];
void inp(){
// cin>>n>>m>>KK>>HH;
HH++;
for(int i=1;i<=n;i++){
// cin>>ar[i];
e[i].clear();
}
for(int i=1;i<=m;i++){
//cin>>xar[i]>>yar[i]>>car[i];
xar[i]++;yar[i]++;
e[xar[i]].push_back({yar[i],car[i]});
e[yar[i]].push_back({xar[i],car[i]});
}
}
int uf[200005];
int fin(int x){
if(uf[x]==x){return x;}
uf[x]=fin(uf[x]);
return uf[x];
}
void mrg(int a,int b){
int pa=fin(a);int pb=fin(b);
if(pa==pb){return;}
uf[pa]=pb;
}
int dis[110][100005];
int vis[110][100005];
double slv(){
for(int i=1;i<=n;i++){
uf[i]=i;
}
for(int i=1;i<=m;i++){
mrg(xar[i],yar[i]);
}
if(fin(1)!=fin(HH)){
return -1;
}
priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int>>>,greater<pair<int,pair<int,int>>>>pq;
KK=min(KK,70ll);
for(int k=0;k<=KK;k++){
for(int i=1;i<=n;i++){
dis[k][i]=1e18;
vis[k][i]=0;
}
}
dis[0][1]=0;
pq.push({0,{0,1}});
for(int i=2;i<=n;i++){
if(ar[i]==0&&fin(i)==fin(1)){
pq.push({0,{0,i}});
dis[0][i]=0;
}
}
while(pq.size()){
int nw=pq.top().second.second;
int nwk=pq.top().second.first;
pq.pop();
if(vis[nwk][nw]){continue;}
vis[nwk][nw]=1;
if(nw==HH){continue;}
for(int i=0;i<e[nw].size();i++){
int v=e[nw][i].first;
int w=e[nw][i].second;
if(vis[nwk][v]){continue;}
if(dis[nwk][v]>dis[nwk][nw]+w){
dis[nwk][v]=dis[nwk][nw]+w;
pq.push({dis[nwk][v],{nwk,v}});
}
}
if(nwk<KK&&ar[nw]==2&&dis[nwk+1][nw]>dis[nwk][nw]){
dis[nwk+1][nw]=dis[nwk][nw];
pq.push({dis[nwk+1][nw],{nwk+1,nw}});
}
}
double ans=dis[0][HH];
for(int i=1;i<=KK;i++){
if(dis[i][HH]>=1e18){continue;}
double cal=dis[i][HH];
for(int j=1;j<=i;j++){
cal/=2.;
}
ans=min(ans,cal);
}
return ans;
}
#define int int
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){
n=n;m=M;KK=K;HH=H;
for(int i=0;i<x.size();i++){
xar[i+1]=x[i];
yar[i+1]=y[i];
car[i+1]=c[i];
}
for(int i=0;i<arr.size();i++){
ar[i+1]=arr[i];
}
inp();
return slv();
}
/*
signed main()
{
inp();
cout<<slv();
return 0;
}
*/
Compilation message
cyberland.cpp:102: warning: "int" redefined
102 | #define int int
|
cyberland.cpp:4: note: this is the location of the previous definition
4 | #define int long long
|
cyberland.cpp: In function 'double slv()':
cyberland.cpp:77:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for(int i=0;i<e[nw].size();i++){
| ~^~~~~~~~~~~~~
cyberland.cpp: In function 'double solve(int, int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
cyberland.cpp:105:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
105 | for(int i=0;i<x.size();i++){
| ~^~~~~~~~~
cyberland.cpp:110:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
110 | for(int i=0;i<arr.size();i++){
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
5844 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
7252 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
21 ms |
7612 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
11820 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
7536 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
24 ms |
7756 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
21 ms |
7508 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
7620 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |