Submission #751785

# Submission time Handle Problem Language Result Execution time Memory
751785 2023-06-01T12:59:02 Z 1075508020060209tc Cyberland (APIO23_cyberland) C++17
0 / 100
31 ms 11596 KB
#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long



int n;int m;int KK;int HH;
ll ar[200005];
ll xar[200005];ll yar[200005];ll car[200005];
vector<pair<int,ll>>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;
}

ll 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<ll,pair<int,int>>,vector<pair<ll,pair<int,int>>>,greater<pair<ll,pair<int,int>>>>pq;
KK=min(KK,70);
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: In function 'double slv()':
cyberland.cpp:77:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<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++){
      |                 ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 5972 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 7252 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 7604 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 11596 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 7476 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 7732 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 7612 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 7672 KB Wrong Answer.
2 Halted 0 ms 0 KB -