Submission #308049

# Submission time Handle Problem Language Result Execution time Memory
308049 2020-09-30T01:00:27 Z daniel920712 Dreaming (IOI13_dreaming) C++14
18 / 100
1000 ms 9720 KB
#include "dreaming.h"
#include <vector>
#include <stdio.h>
using namespace std;
vector < pair < int , int > > Next[100005];
vector < int > all;
bool have[100005]={0};
int a=0,b=0,c=0,t=0,big=0,bb=0,where;
void F(int here,int con)
{
    all.push_back(here);
    if(con>=big)
    {
        big=con;
        where=here;
    }
    have[here]=1;
    for(auto i:Next[here]) if(!have[i.first]) F(i.first,con+i.second);
}
void F2(int here,int Father,int con)
{
    t=min(t,max(con,big-con));
    for(auto i:Next[here]) if(i.first!=Father) F2(i.first,here,con+i.second);
}
void F3(int here,int Father,int con)
{
    big=max(big,con);
    for(auto i:Next[here]) if(i.first!=Father) F3(i.first,here,con+i.second);
}
int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
    int i,how=0;

    for(i=0;i<M;i++)
    {
        Next[A[i]].push_back(make_pair(B[i],T[i]));
        Next[B[i]].push_back(make_pair(A[i],T[i]));
    }
    for(i=0;i<N;i++)
    {
        if(!have[i])
        {
            how++;
            big=0;
            where=0;
            all.clear();
            F(i,0);
            t=1e9;
            for(auto j:all)
            {
                big=0;
                F3(i,-1,0);
                t=min(t,big);
            }
            if(t>=a)
            {
                c=b;
                b=a;
                a=t;
            }
            else if(t>=b)
            {
                c=b;
                b=t;
            }
            else if(t>=c) c=t;
        }
    }
    if(how>=2) bb=max(bb,a+b+L);
    if(how>=3) bb=max(bb,b+c+2*L);
    return bb;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:49:22: warning: unused variable 'j' [-Wunused-variable]
   49 |             for(auto j:all)
      |                      ^
# Verdict Execution time Memory Grader output
1 Execution timed out 1096 ms 9720 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1096 ms 9720 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1096 ms 9720 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 5048 KB Output is correct
2 Correct 25 ms 5120 KB Output is correct
3 Correct 31 ms 5112 KB Output is correct
4 Correct 24 ms 5120 KB Output is correct
5 Correct 24 ms 5120 KB Output is correct
6 Correct 28 ms 5240 KB Output is correct
7 Correct 26 ms 5240 KB Output is correct
8 Correct 25 ms 4988 KB Output is correct
9 Correct 25 ms 4992 KB Output is correct
10 Correct 25 ms 5248 KB Output is correct
11 Correct 2 ms 2688 KB Output is correct
12 Correct 4 ms 2816 KB Output is correct
13 Correct 4 ms 2816 KB Output is correct
14 Correct 3 ms 2816 KB Output is correct
15 Correct 4 ms 2816 KB Output is correct
16 Correct 4 ms 2816 KB Output is correct
17 Correct 4 ms 2816 KB Output is correct
18 Correct 4 ms 3072 KB Output is correct
19 Correct 4 ms 2816 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
21 Correct 2 ms 2688 KB Output is correct
22 Correct 2 ms 2688 KB Output is correct
23 Correct 4 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1096 ms 9720 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1096 ms 9720 KB Time limit exceeded
2 Halted 0 ms 0 KB -