Submission #962135

# Submission time Handle Problem Language Result Execution time Memory
962135 2024-04-13T07:23:00 Z simona1230 Dreaming (IOI13_dreaming) C++17
10 / 100
1000 ms 17608 KB
#include <bits/stdc++.h>
#include "dreaming.h"

using namespace std;
long long n,m,k;
vector<pair<long long,long long> > v[100001];
long long l[100001];
long long c[100001],num;
long long in;


void prec(long long i,long long p)
{
    c[i]=num;
    for(long long j=0; j<v[i].size(); j++)
    {
        long long nb=v[i][j].first;
        if(nb!=p)
        {
            prec(nb,i);
        }
    }
}

long long minn[100001];
long long dfs(long long i,long long p)
{
    if(v[i].size()==1&&p||v[i].size()==0)return 0;
    long long curr=0,f1=0,f2=0;
    for(long long j=0; j<v[i].size(); j++)
    {
        long long nb=v[i][j].first;
        if(nb==p)continue;
        long long f=dfs(nb,i)+v[i][j].second;
        curr=max(curr,f);
        if(f>=f1)
        {
            f2=f1;
            f1=f;
        }
        else if(f>=f2)
        {
            f2=f;
        }
    }
    in=max(in,f1+f2);
    //cout<<i<<" - "<<curr<<endl;
    return curr;
}

long long solve()
{
    for(long long i=1; i<=num; i++)
        minn[i]=1e9;

    for(long long i=1; i<=n; i++)
    {
        //cout<<c[i]<<" "<<i<<" "<<dfs(i,0)<<endl;
        minn[c[i]]=min(minn[c[i]],dfs(i,0));
    }

    sort(minn+1,minn+num+1);
    return max(k+minn[num]+minn[num-1],in);
}

int travelTime(int N,int M,int L,int A[],int B[],int T[])
{
    n=N;
    m=M;
    k=L;
    //cout<<n<<" "<<m<<" "<<k<<endl;

    for(long long i=0;i<m;i++)
    {
        A[i]++;
        B[i]++;
        //cout<<A[i]<<" "<<B[i]<<" "<<T[i]<<endl;
        v[A[i]].push_back({B[i],T[i]});
        v[B[i]].push_back({A[i],T[i]});
    }

    for(long long i=1; i<=n; i++)
        if(!c[i])
        {
            num++;
            prec(i,0);
        }
    return solve();
}


/*
12 8 2
0 8 4
8 2 2
2 7 4
5 11 3
5 1 7
1 3 1
1 9 5
10 6 3
*/

Compilation message

dreaming.cpp: In function 'void prec(long long int, long long int)':
dreaming.cpp:15:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for(long long j=0; j<v[i].size(); j++)
      |                        ~^~~~~~~~~~~~
dreaming.cpp: In function 'long long int dfs(long long int, long long int)':
dreaming.cpp:28:22: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   28 |     if(v[i].size()==1&&p||v[i].size()==0)return 0;
      |        ~~~~~~~~~~~~~~^~~
dreaming.cpp:30:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(long long j=0; j<v[i].size(); j++)
      |                        ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1055 ms 17608 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5980 KB Output is correct
2 Correct 2 ms 6132 KB Output is correct
3 Correct 2 ms 5980 KB Output is correct
4 Correct 1 ms 5980 KB Output is correct
5 Correct 2 ms 5980 KB Output is correct
6 Correct 2 ms 5980 KB Output is correct
7 Correct 1 ms 5976 KB Output is correct
8 Correct 1 ms 5980 KB Output is correct
9 Correct 1 ms 5980 KB Output is correct
10 Correct 2 ms 5980 KB Output is correct
11 Correct 1 ms 5980 KB Output is correct
12 Correct 1 ms 5980 KB Output is correct
13 Correct 1 ms 5980 KB Output is correct
14 Correct 1 ms 6232 KB Output is correct
15 Correct 1 ms 3928 KB Output is correct
16 Correct 2 ms 5980 KB Output is correct
17 Correct 2 ms 5980 KB Output is correct
18 Correct 2 ms 5980 KB Output is correct
19 Correct 2 ms 6060 KB Output is correct
20 Correct 2 ms 5980 KB Output is correct
21 Correct 2 ms 5980 KB Output is correct
22 Correct 2 ms 5980 KB Output is correct
23 Correct 2 ms 5976 KB Output is correct
24 Correct 2 ms 5980 KB Output is correct
25 Correct 1 ms 5976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1055 ms 17608 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 8024 KB Output is correct
2 Incorrect 15 ms 8028 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5980 KB Output is correct
2 Correct 2 ms 6132 KB Output is correct
3 Correct 2 ms 5980 KB Output is correct
4 Correct 1 ms 5980 KB Output is correct
5 Correct 2 ms 5980 KB Output is correct
6 Correct 2 ms 5980 KB Output is correct
7 Correct 1 ms 5976 KB Output is correct
8 Correct 1 ms 5980 KB Output is correct
9 Correct 1 ms 5980 KB Output is correct
10 Correct 2 ms 5980 KB Output is correct
11 Correct 1 ms 5980 KB Output is correct
12 Correct 1 ms 5980 KB Output is correct
13 Correct 1 ms 5980 KB Output is correct
14 Correct 1 ms 6232 KB Output is correct
15 Correct 1 ms 3928 KB Output is correct
16 Correct 2 ms 5980 KB Output is correct
17 Correct 2 ms 5980 KB Output is correct
18 Correct 2 ms 5980 KB Output is correct
19 Correct 2 ms 6060 KB Output is correct
20 Correct 2 ms 5980 KB Output is correct
21 Correct 2 ms 5980 KB Output is correct
22 Correct 2 ms 5980 KB Output is correct
23 Correct 2 ms 5976 KB Output is correct
24 Correct 2 ms 5980 KB Output is correct
25 Correct 1 ms 5976 KB Output is correct
26 Correct 3 ms 5980 KB Output is correct
27 Correct 3 ms 5980 KB Output is correct
28 Correct 3 ms 6236 KB Output is correct
29 Correct 2 ms 5980 KB Output is correct
30 Correct 3 ms 5980 KB Output is correct
31 Correct 3 ms 6236 KB Output is correct
32 Incorrect 3 ms 5980 KB Output isn't correct
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1055 ms 17608 KB Time limit exceeded
2 Halted 0 ms 0 KB -