Submission #962930

# Submission time Handle Problem Language Result Execution time Memory
962930 2024-04-14T09:52:07 Z vivkostov Dreaming (IOI13_dreaming) C++14
0 / 100
49 ms 15184 KB
#include<bits/stdc++.h>
#include "dreaming.h"
using namespace std;
void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
struct cell
{
    long long int to,cost;
};
long long int n,m,l,a1[100005],a2[100005],a3[100005],ma[100005],sma[100005],used[100005],up[100005],otg[100005];
vector<cell>v[100005];
void find_ma(long long int beg)
{
    used[beg]=1;
    long long int w;
    for(long long int i=0;i<(long long int)(v[beg].size());i++)
    {
        w=v[beg][i].to;
        if(!used[w])
        {
            find_ma(w);
            if(ma[beg]<ma[w]+v[beg][i].cost)
            {
                sma[beg]=ma[beg];
                ma[beg]=ma[w]+v[beg][i].cost;
            }
            else if(sma[beg]<ma[w]+v[beg][i].cost)
            {
                sma[beg]=ma[w]+v[beg][i].cost;
            }
        }
    }
}
void find_up(long long int beg,long long int par,long long int cos)
{
    used[beg]=1;
    long long int w;
    if(ma[par]-cos!=ma[beg])
    {
        up[beg]=max(up[par],ma[par])+cos;
    }
    else
    {
        up[beg]=max(up[par],sma[par])+cos;
    }
    for(long long int i=0;i<(long long int)(v[beg].size());i++)
    {
        w=v[beg][i].to;
        if(!used[w])
        {
            find_up(w,beg,v[beg][i].cost);
        }
    }
}
void find_otg(long long int beg,long long int lead)
{
    used[beg]=1;
    long long int w;
    for(long long int i=0;i<(long long int)(v[beg].size());i++)
    {
        w=v[beg][i].to;
        if(!used[w])
        {
            find_otg(w,lead);
        }
    }
    otg[lead]=min(otg[lead],max(max(ma[beg],sma[beg]),up[beg]));
}
int travelTime(int n,int m,int l,int a1[],int a2[],int a3[])
//void read()
{
    //cin>>n>>m>>l;
    cell h;
    for(long long int i=1;i<=m;i++)
    {
        //cin>>a1[i]>>a2[i]>>a3[i];
        a1[i]++;
        a2[i]++;
        h.to=a2[i];
        h.cost=a3[i];
        v[a1[i]].push_back(h);
        h.to=a1[i];
        v[a2[i]].push_back(h);
    }
    for(long long int i=1;i<=n;i++)
    {
        if(!used[i])
        {
            find_ma(i);
        }
    }
    memset(used,0,sizeof(used));
    for(long long int i=1;i<=n;i++)
    {
        if(!used[i])
        {
            find_up(i,0,0);
        }
    }
    memset(used,0,sizeof(used));
    for(long long int i=1;i<=n;i++)
    {
        if(!used[i])
        {
            otg[i]=max(max(ma[i],sma[i]),up[i]);
            find_otg(i,i);
        }
    }
    sort(otg+1,otg+n+1);
    long long int aa=0;
    for(long long int i=1;i<=n;i++)
    {
        aa=max(aa,ma[i]+sma[i]);
    }
    if(n!=m+2)
    {
        aa=max(aa,2*l+otg[n-2]+otg[n-1]);
    }
    aa=max(aa,l+otg[n-1]+otg[n]);
    //cout<<aa<<endl;
    return aa;
}
/*int main()
{
    speed();
    read();
    return 0;
}
*/
# Verdict Execution time Memory Grader output
1 Correct 43 ms 15184 KB Output is correct
2 Correct 49 ms 15180 KB Output is correct
3 Correct 25 ms 13072 KB Output is correct
4 Correct 9 ms 6800 KB Output is correct
5 Correct 5 ms 6240 KB Output is correct
6 Incorrect 11 ms 7512 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 5212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 43 ms 15184 KB Output is correct
2 Correct 49 ms 15180 KB Output is correct
3 Correct 25 ms 13072 KB Output is correct
4 Correct 9 ms 6800 KB Output is correct
5 Correct 5 ms 6240 KB Output is correct
6 Incorrect 11 ms 7512 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 9436 KB Output is correct
2 Correct 17 ms 9560 KB Output is correct
3 Correct 16 ms 9568 KB Output is correct
4 Correct 16 ms 9632 KB Output is correct
5 Correct 17 ms 9568 KB Output is correct
6 Correct 17 ms 9820 KB Output is correct
7 Correct 17 ms 9812 KB Output is correct
8 Correct 21 ms 9416 KB Output is correct
9 Correct 16 ms 9304 KB Output is correct
10 Correct 22 ms 9816 KB Output is correct
11 Correct 1 ms 5212 KB Output is correct
12 Correct 4 ms 7512 KB Output is correct
13 Correct 5 ms 7260 KB Output is correct
14 Correct 6 ms 7004 KB Output is correct
15 Correct 4 ms 7260 KB Output is correct
16 Correct 6 ms 7004 KB Output is correct
17 Correct 4 ms 6400 KB Output is correct
18 Correct 6 ms 7516 KB Output is correct
19 Correct 4 ms 7004 KB Output is correct
20 Incorrect 1 ms 5212 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 5212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 43 ms 15184 KB Output is correct
2 Correct 49 ms 15180 KB Output is correct
3 Correct 25 ms 13072 KB Output is correct
4 Correct 9 ms 6800 KB Output is correct
5 Correct 5 ms 6240 KB Output is correct
6 Incorrect 11 ms 7512 KB Output isn't correct
7 Halted 0 ms 0 KB -