답안 #962081

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
962081 2024-04-13T06:44:53 Z simona1230 꿈 (IOI13_dreaming) C++17
0 / 100
1000 ms 13944 KB
#include <bits/stdc++.h>
#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:13: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]
   13 |     for(int j=0; j<v[i].size(); j++)
      |                  ~^~~~~~~~~~~~
dreaming.cpp: In function 'int dfs(int, 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: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]
   28 |     for(int j=0; j<v[i].size(); j++)
      |                  ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1065 ms 13944 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 5208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1065 ms 13944 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 7260 KB Output is correct
2 Incorrect 13 ms 7260 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 5208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1065 ms 13944 KB Time limit exceeded
2 Halted 0 ms 0 KB -