답안 #962105

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
962105 2024-04-13T07:05:31 Z simona1230 꿈 (IOI13_dreaming) C++17
0 / 100
1000 ms 14488 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;

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 furt[100001],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;
    for(long long j=0; j<v[i].size(); j++)
    {
        long long 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;
}

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

    for(long long 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;
    //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:13: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]
   13 |     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:26:22: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   26 |     if(v[i].size()==1&&p||v[i].size()==0)return 0;
      |        ~~~~~~~~~~~~~~^~~
dreaming.cpp:28: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]
   28 |     for(long long j=0; j<v[i].size(); j++)
      |                        ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1057 ms 14488 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1057 ms 14488 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 7516 KB Output is correct
2 Incorrect 14 ms 7516 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1057 ms 14488 KB Time limit exceeded
2 Halted 0 ms 0 KB -