Submission #984818

# Submission time Handle Problem Language Result Execution time Memory
984818 2024-05-17T06:03:08 Z Muhammad_Aneeq Cyberland (APIO23_cyberland) C++17
44 / 100
32 ms 11092 KB
#include "cyberland.h"
#include <vector>
#include <map>
#include <set>
#include <iostream>
using namespace std;
int const MAXN=1e5+10;
double const inf=1e18;
vector<pair<int,int>>nei[MAXN];
int val[MAXN];
double dis[MAXN]={};
bool vis[MAXN]={},ra[MAXN]={};
int h;
double ans=inf;
map<pair<int,int>,int>d;
void dfs(int x)
{
    ra[x]=1;
    vis[x]=1;
    for (auto [i,j]:nei[x])
    {
        if (!vis[i])
            dfs(i);
    }
}
vector<int>p;
int k;
void bfs(int x)
{
      set<pair<double,int>>S;
      dis[x]=0;
      S.insert({dis[x],x});
      while (S.size())
      {
        int z=(*begin(S)).second;
        S.erase(*begin(S));
        if (vis[z])
            continue;
        vis[z]=1;
        for (auto [i,j]:nei[z])
        {
            if (dis[i]>dis[z]+j)
            {
                dis[i]=dis[z]+j;
                S.insert({dis[i],i});
            }
        }
      }
}
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) 
{
    ans=inf;
    h=H;
    k=K;
    d={};
    p={};
    bool tw=0;
    for (int i=0;i<N;i++)
    {
        nei[i]={};
        val[i]=arr[i];
        vis[i]=0;
        dis[i]=inf;
        ra[i]=0;
        if (val[i]==0)
            tw=1;
    }
    for (int i=0;i<x.size();i++)
    {  
        nei[x[i]].push_back({y[i],c[i]});
        nei[y[i]].push_back({x[i],c[i]});
    }
    vis[h]=1;
    dfs(0);
    for (int i=0;i<N;i++)
        vis[i]=0;
    bfs(h);
    if (dis[0]==inf)
        return -1;
    ans=dis[0];
    for (int i=1;i<N;i++)
    {
        if (ra[i]&&val[i]==0)
            ans=min(ans,dis[i]);
    }
    return ans;
}

Compilation message

cyberland.cpp: In function 'double solve(int, int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
cyberland.cpp:68:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for (int i=0;i<x.size();i++)
      |                  ~^~~~~~~~~
cyberland.cpp:57:10: warning: variable 'tw' set but not used [-Wunused-but-set-variable]
   57 |     bool tw=0;
      |          ^~
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 4184 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 4340 KB Correct.
2 Correct 25 ms 4080 KB Correct.
3 Correct 23 ms 3928 KB Correct.
4 Correct 24 ms 4184 KB Correct.
5 Correct 24 ms 3928 KB Correct.
6 Correct 21 ms 4700 KB Correct.
7 Correct 27 ms 4700 KB Correct.
8 Correct 12 ms 5324 KB Correct.
9 Correct 22 ms 3932 KB Correct.
10 Correct 23 ms 3932 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 24 ms 4956 KB Correct.
2 Correct 23 ms 4956 KB Correct.
3 Correct 22 ms 4432 KB Correct.
4 Correct 25 ms 4956 KB Correct.
5 Correct 25 ms 4956 KB Correct.
6 Correct 6 ms 4700 KB Correct.
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 7764 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 4188 KB Correct.
2 Correct 22 ms 4168 KB Correct.
3 Correct 20 ms 4176 KB Correct.
4 Correct 23 ms 4700 KB Correct.
5 Correct 21 ms 4048 KB Correct.
# Verdict Execution time Memory Grader output
1 Correct 21 ms 4952 KB Correct.
2 Correct 19 ms 5096 KB Correct.
3 Correct 32 ms 11092 KB Correct.
4 Correct 15 ms 5208 KB Correct.
5 Correct 20 ms 4956 KB Correct.
6 Correct 21 ms 4956 KB Correct.
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 4952 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 4952 KB Wrong Answer.
2 Halted 0 ms 0 KB -