답안 #968274

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
968274 2024-04-23T09:14:37 Z Hugo1729 꿈 (IOI13_dreaming) C++11
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
#define f first
#define s second

vector<pair<int,int>> adj[100000];

int dp1[100000],dp2[100000],dp3[100000],dp4[100000];
bool marked[100000]={0};

int dfs_sizes1(int v, int pV){
    dp1[v]=0;
    dp2[v]=0;
    marked[v]=1;
    for(auto [w,d] : adj[v]){
        if(w!=pV){
            int sus=dfs_sizes1(w,v)+d;
            if(sus>dp1[v]){
                dp2[v]=dp1[v];
                dp1[v]=sus;
            }else if(sus>dp2[v]){
                dp2[v]=sus;
            }
        }
    }
    return dp1[v];
}

void dfs_sizes2(int v, int pV){
    for(auto [w,d] : adj[v]){
        if(w!=pV){
            if(dp1[w]+d==dp1[v]){
                dp3[w]=max(dp2[v],dp3[v])+d;
            }else{
                dp3[w]=max(dp1[v],dp3[v])+d;
            }
            dfs_sizes2(w,v);
        }
    }
    dp4[v]=dp1[v]+max(dp3[v],dp2[v]);
}

int dfs_final(int v, int pV){
    int ans=max(dp1[v],dp3[v]);

    for(auto [w,d] : adj[v]){
        if(w!=pV){
            ans=min(ans,dfs_final(w,v));
        }
    }

    return ans;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    for(int i=0;i<M;i++){
        adj[A[i]].push_back({B[i],T[i]});
        adj[B[i]].push_back({A[i],T[i]});
    }

    vector<int> sussy;

    int amongus=0;

    for(int i=0;i<N;i++){
        if(!marked[i]){
            dfs_sizes1(i,i);
            dfs_sizes2(i,i);
            sussy.push_back(-dfs_final(i,i));
            // cout <<i << ' ' << sussy[sussy.size()-1] << '\n';
        }
        amongus=max(amongus,dp4[i]);

        // cout << i << ' ' << dp1[i].first << ' ' << dp1[i].second << '\n';

    }

    for(int i=0;i<N;i++){
        // cout << i << ' ' << dp1[i] << ' ' << dp2[i] << ' ' << dp3[i] << '\n';
    }

    sort(sussy.begin(),sussy.end());

    if(sussy.size()==1)return amongus;
    else if(sussy.size()==2)return max(-sussy[0]-sussy[1]+L,amongus);

    return max(-sussy[0]-sussy[1]+L,-sussy[2]-sussy[1]+L*2,amongus);
}

Compilation message

dreaming.cpp: In function 'int dfs_sizes1(int, int)':
dreaming.cpp:16:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   16 |     for(auto [w,d] : adj[v]){
      |              ^
dreaming.cpp: In function 'void dfs_sizes2(int, int)':
dreaming.cpp:31:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   31 |     for(auto [w,d] : adj[v]){
      |              ^
dreaming.cpp: In function 'int dfs_final(int, int)':
dreaming.cpp:47:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   47 |     for(auto [w,d] : adj[v]){
      |              ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from dreaming.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h: In instantiation of 'const _Tp& std::max(const _Tp&, const _Tp&, _Compare) [with _Tp = int; _Compare = int]':
dreaming.cpp:88:67:   required from here
/usr/include/c++/10/bits/stl_algobase.h:303:17: error: '__comp' cannot be used as a function
  303 |       if (__comp(__a, __b))
      |           ~~~~~~^~~~~~~~~~