Submission #962068

# Submission time Handle Problem Language Result Execution time Memory
962068 2024-04-13T06:37:17 Z simona1230 Dreaming (IOI13_dreaming) C++17
0 / 100
1000 ms 14164 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include"dreaming.h"
using namespace std;

int n,m,k;
vector<pair<int,int> > v[100001];
int l[100001];
int c[100001],num;

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

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

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

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

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

int travelTime(int N,int M,int L,int A[],int B[],int T[])
{
    n=N;
    m=M;
    k=L;

    for(int i=0;i<m;i++)
    {
        A[i]++;
        B[i]++;
        v[A[i]].push_back({B[i],T[i]});
        v[B[i]].push_back({A[i],T[i]});
    }

    for(int 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(int, int)':
dreaming.cpp:15:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for(int j=0; j<v[i].size(); j++)
      |                  ~^~~~~~~~~~~~
dreaming.cpp: In function 'int dfs(int, 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:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(int j=0; j<v[i].size(); j++)
      |                  ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1054 ms 14164 KB Time limit exceeded
2 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 Execution timed out 1054 ms 14164 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 7400 KB Output is correct
2 Incorrect 14 ms 7256 KB Output isn't correct
3 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 Execution timed out 1054 ms 14164 KB Time limit exceeded
2 Halted 0 ms 0 KB -