Submission #1115923

# Submission time Handle Problem Language Result Execution time Memory
1115923 2024-11-21T05:10:41 Z Faisal_Saqib Cyberland (APIO23_cyberland) C++17
49 / 100
39 ms 12880 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];
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;
    for(int j=0;j<n;j++)
    {
        if(dist[j]!=inf and (j==0 or arr[j]==0))
        {
            dist[j]=0;
            pq.push({0,j});            
        }
        else
            dist[j]=inf;
    }
    while(pq.size())
    {
        auto tp=pq.top();
        pq.pop();
        if(tp.first==dist[tp.second])
        {
            if(tp.second==e)
            {
                continue;
            }
            int v=tp.second;
            if(arr[v]==2)
            {
                dist[v]/=2;
                tp.first/=2;
            }
            for(auto [u,w]:adj[v])
            {
                if((dist[v]+w)<dist[u])
                {
                    dist[u]=dist[v]+w;
                    pq.push({dist[u],u});
                }
            }
        }
    }
    return ((dist[e]==inf)?MS:dist[e]);
}
double solve(int NP, int m, int k, int h, vector<int> x, vector<int> y, vector<int> c, vector<int> AS) {
    n=NP;
    // DONT FORGET TO CLEAR THE THINGS YOU USED
    for(int i=n-1;i>=0;i--)
    {
        if(AS[i]==2)
        {
            if(k==0)
            {
                AS[i]=1;
            }
            else
                k--;
        }
    }
    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 Correct 14 ms 4944 KB Correct.
2 Correct 14 ms 4944 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 25 ms 5456 KB Correct.
2 Correct 31 ms 5712 KB Correct.
3 Correct 31 ms 5608 KB Correct.
4 Correct 32 ms 5712 KB Correct.
5 Correct 31 ms 5704 KB Correct.
6 Correct 31 ms 6480 KB Correct.
7 Correct 39 ms 6728 KB Correct.
8 Correct 18 ms 6992 KB Correct.
9 Correct 26 ms 5456 KB Correct.
10 Correct 24 ms 5456 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 34 ms 5600 KB Correct.
2 Correct 29 ms 5880 KB Correct.
3 Correct 28 ms 5704 KB Correct.
4 Correct 26 ms 5456 KB Correct.
5 Correct 26 ms 5448 KB Correct.
6 Correct 8 ms 5884 KB Correct.
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 10956 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 5712 KB Correct.
2 Correct 23 ms 5712 KB Correct.
3 Correct 24 ms 5712 KB Correct.
4 Correct 25 ms 6952 KB Correct.
5 Correct 19 ms 5200 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 24 ms 5712 KB Correct.
2 Correct 20 ms 5780 KB Correct.
3 Correct 31 ms 12880 KB Correct.
4 Correct 17 ms 6488 KB Correct.
5 Correct 21 ms 5508 KB Correct.
6 Correct 22 ms 5712 KB Correct.
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 5720 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 5712 KB Wrong Answer.
2 Halted 0 ms 0 KB -