Submission #1115935

# Submission time Handle Problem Language Result Execution time Memory
1115935 2024-11-21T05:27:06 Z Faisal_Saqib Cyberland (APIO23_cyberland) C++17
44 / 100
161 ms 35656 KB
#include "cyberland.h"
#include <bits/stdc++.h>
 
 
//#include "stub.cpp"
 
using namespace std;
const int N=1e5+10;
const long double inf=1e18;
int n,arr[N],k;
vector<pair<int,long long>> adj[N];
long double dist[N],MS=-1;
long double dyk(int s,int e)
{
    for(int j=0;j<n;j++)
        dist[j]=inf;
    priority_queue<pair<long double,int>,vector<pair<long double,int>>,greater<pair<long double,int>>> pq;
    dist[s]=0;
    pq.push({dist[s],s});
    while(pq.size())
    {
        auto tp=pq.top();
        pq.pop();
        if(tp.second==e) // this is cz we dont go other side of h
            continue;
        if(tp.first==dist[tp.second])
        {
            int v=tp.second;
            for(auto [u,w]:adj[v])
            {
                if((dist[v]+w)<dist[u])
                {
                    dist[u]=dist[v]+w;
                    pq.push({dist[u],u});
                }
            }
        }
    }
    // cout<<"DY from "<<s<<endl;
    // for(int pp=0;pp<n;pp++)
    // {
    //     cout<<dist[pp]<<' ';
    // }
    // cout<<endl;
    return ((dist[e]==inf)?MS:dist[e]);
}
long double dyk_comb(int e)
{
    dyk(0,e);
    priority_queue<pair<long double,int>,vector<pair<long double,int>>,greater<pair<long double,int>>> pq[k+1];
    for(int j=0;j<n;j++)
    {
        if(dist[j]!=inf and (j==0 or arr[j]==0))
        {
            dist[j]=0;
            pq[k].push({0,j});            
        }
        else
            dist[j]=inf;
    }
    for(int j=k;j>=0;j--)
    {

        while(pq[j].size())
        {
            auto tp=pq[j].top();
            pq[j].pop();
            if(tp.first==dist[tp.second])
            {
                // if(tp.second==e)
                // {
                //     continue;
                // }
                int v=tp.second;
                for(auto [u,w]:adj[v])
                {
                    if((dist[v]+w)<dist[u])
                    {
                        dist[u]=dist[v]+w;
                        pq[j].push({dist[u],u});
                    }
                }
                if(arr[v]==2 and j>0)
                {
                    dist[v]/=2;
                    pq[j-1].push({dist[v]/2.0,v});
                }
            }
        }
    }
    return ((dist[e]==inf)?MS:dist[e]);
}
double solve(int NP, int m, int kp, int h, vector<int> x, vector<int> y, vector<int> c, vector<int> AS) {
    n=NP;
    k=kp;
    for(int i=0;i<n;i++)
    {
        arr[i]=AS[i];
        adj[i].clear();
    }
    for(int j=0;j<m;j++)
    {
        adj[x[j]].push_back({y[j],c[j]});
        adj[y[j]].push_back({x[j],c[j]});
    }
    return dyk_comb(h);
}
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 4688 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 4688 KB Correct.
2 Correct 30 ms 4892 KB Correct.
3 Correct 31 ms 4688 KB Correct.
4 Correct 29 ms 4688 KB Correct.
5 Correct 29 ms 4688 KB Correct.
6 Correct 28 ms 5556 KB Correct.
7 Correct 37 ms 5704 KB Correct.
8 Correct 18 ms 6480 KB Correct.
9 Correct 23 ms 4432 KB Correct.
10 Correct 22 ms 4432 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 32 ms 4752 KB Correct.
2 Correct 28 ms 4784 KB Correct.
3 Correct 27 ms 4944 KB Correct.
4 Correct 25 ms 4432 KB Correct.
5 Correct 25 ms 4604 KB Correct.
6 Correct 8 ms 5712 KB Correct.
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 10452 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 4688 KB Correct.
2 Correct 23 ms 4688 KB Correct.
3 Correct 23 ms 4688 KB Correct.
4 Correct 25 ms 5988 KB Correct.
5 Correct 20 ms 4432 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 23 ms 4688 KB Correct.
2 Correct 20 ms 4812 KB Correct.
3 Correct 40 ms 11144 KB Correct.
4 Correct 16 ms 5804 KB Correct.
5 Correct 23 ms 4432 KB Correct.
6 Correct 23 ms 4908 KB Correct.
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 4988 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 161 ms 35656 KB Wrong Answer.
2 Halted 0 ms 0 KB -