Submission #757526

# Submission time Handle Problem Language Result Execution time Memory
757526 2023-06-13T09:41:16 Z MShevchenko Dreaming (IOI13_dreaming) C++17
0 / 100
33 ms 13924 KB
#include"dreaming.h"
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
int inf = 1e9;
vector<vector<pair<int, int>>> g;
vector<int> v;
vector<bool> u;
int N, M, L;
int h(int x)
{

    int v1,v2,l;
    vector<int> d1(N, inf),d2(N, inf),p(N);
    queue<int> q1,q2;
    d1[x]=0;
    q1.push(x);
    while(!q1.empty())
    {
        int v=q1.front();
        u[v]=1;
        q1.pop();
        for(pair<int, int> i:g[v])
        {
            if(d1[i.ff]>d1[v]+i.ss)
            {
                d1[i.ff]=d1[v]+i.ss;
                q1.push(i.ff);
            }
        }
    }
    int mx=-inf;
    for(int i=0;i<N;i++)
    if(d1[i]<inf){
        if(mx<d1[i]){
            mx=d1[i];
            v1=i;
        }
    }

    q2.push(v1);
    d2[v1]=0;
    while(!q2.empty())
    {
        int v=q2.front();
        q2.pop();
        for(pair<int, int> i:g[v])
        {
            if(d2[i.ff]>d2[v]+i.ss)
            {
                d2[i.ff]=d2[v]+i.ss;
                q2.push(i.ff);
                p[i.ff]=v;
            }
        }
    }
    mx=-inf;

    for(int i=0;i<N;i++)
    if(d2[i]<inf){
        if(mx<d2[i]){
            mx=d2[i];
            v2=i;
        }
    }
    l=mx;

    int v=v2,d=0,mn=inf;

    for(int i=v2;i!=v1;i=p[i])
    {

        int num;
        for(auto j:g[p[i]])
        if(j.ff==i){
            num=j.ss;
            break;
        }

        l-=num;
        d+=num;
        if(mn>max(l,d)){
            v=p[i];
            mn=max(l,d);
        }
    }

    if(v==v2)return 0;
    return mn;
}
int travelTime(int N,int M,int L,int A[],int B[],int T[])
{
    g.resize(N);
    u.resize(N,0);

    for(int i=0;i<M;i++)
    {
        g[A[i]].push_back({B[i],T[i]});
        g[B[i]].push_back({A[i],T[i]});
    }
    for(int i=0;i<N;i++)
        if(!u[i])v.push_back(h(i));
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    if(v.size()==1)return v[0];
    else if(v.size()==2)return v[0]+v[1]+L;
    else return max(v[0]+v[1]+L,v[1]+L+L+v[2]);
}

Compilation message

dreaming.cpp: In function 'int h(int)':
dreaming.cpp:82:10: warning: 'num' may be used uninitialized in this function [-Wmaybe-uninitialized]
   82 |         d+=num;
      |         ~^~~~~
dreaming.cpp:89:5: warning: 'v2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   89 |     if(v==v2)return 0;
      |     ^~
# Verdict Execution time Memory Grader output
1 Runtime error 33 ms 13924 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 444 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 33 ms 13924 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 18 ms 10016 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 444 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 33 ms 13924 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -