Submission #962935

# Submission time Handle Problem Language Result Execution time Memory
962935 2024-04-14T09:57:20 Z vivkostov Dreaming (IOI13_dreaming) C++14
0 / 100
37 ms 12380 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
{
    int to,cost;
};
int n,m,l,ma[100005],sma[100005],used[100005],up[100005],otg[100005],A[100005],B[100005],C[100005];
vector<cell>v[100005];
void find_ma(int beg)
{
    used[beg]=1;
    int w;
    for(int i=0;i<(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(int beg,int par,int cos)
{
    used[beg]=1;
    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(int i=0;i<(int)(v[beg].size());i++)
    {
        w=v[beg][i].to;
        if(!used[w])
        {
            find_up(w,beg,v[beg][i].cost);
        }
    }
}
void find_otg(int beg,int lead)
{
    used[beg]=1;
    int w;
    for(int i=0;i<(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 A[],int B[],int C[])
//void read()
{
    //cin>>n>>m>>l;
    cell h;
    for(int i=1;i<=m;i++)
    {
        //cin>>A[i]>>B[i]>>C[i];
        A[i]++;
        B[i]++;
        h.to=B[i];
        h.cost=C[i];
        v[A[i]].push_back(h);
        h.to=A[i];
        v[B[i]].push_back(h);
    }
    for(int i=1;i<=n;i++)
    {
        if(!used[i])
        {
            find_ma(i);
        }
    }
    memset(used,0,sizeof(used));
    for(int i=1;i<=n;i++)
    {
        if(!used[i])
        {
            find_up(i,0,0);
        }
    }
    memset(used,0,sizeof(used));
    for(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);
    int aa=0;
    for(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 36 ms 12380 KB Output is correct
2 Correct 37 ms 12116 KB Output is correct
3 Correct 23 ms 11100 KB Output is correct
4 Correct 6 ms 6104 KB Output is correct
5 Correct 5 ms 5468 KB Output is correct
6 Incorrect 10 ms 6492 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 36 ms 12380 KB Output is correct
2 Correct 37 ms 12116 KB Output is correct
3 Correct 23 ms 11100 KB Output is correct
4 Correct 6 ms 6104 KB Output is correct
5 Correct 5 ms 5468 KB Output is correct
6 Incorrect 10 ms 6492 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 8280 KB Output is correct
2 Correct 21 ms 8512 KB Output is correct
3 Correct 16 ms 8284 KB Output is correct
4 Correct 16 ms 8348 KB Output is correct
5 Correct 16 ms 8444 KB Output is correct
6 Correct 17 ms 8536 KB Output is correct
7 Correct 17 ms 8540 KB Output is correct
8 Correct 20 ms 8264 KB Output is correct
9 Correct 18 ms 8284 KB Output is correct
10 Correct 17 ms 8456 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 4 ms 6236 KB Output is correct
13 Correct 4 ms 6236 KB Output is correct
14 Correct 4 ms 6236 KB Output is correct
15 Correct 4 ms 6236 KB Output is correct
16 Correct 4 ms 6236 KB Output is correct
17 Correct 4 ms 5720 KB Output is correct
18 Correct 4 ms 6492 KB Output is correct
19 Correct 4 ms 6236 KB Output is correct
20 Incorrect 1 ms 4956 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 36 ms 12380 KB Output is correct
2 Correct 37 ms 12116 KB Output is correct
3 Correct 23 ms 11100 KB Output is correct
4 Correct 6 ms 6104 KB Output is correct
5 Correct 5 ms 5468 KB Output is correct
6 Incorrect 10 ms 6492 KB Output isn't correct
7 Halted 0 ms 0 KB -