Submission #1269014

#TimeUsernameProblemLanguageResultExecution timeMemory
1269014codergDreaming (IOI13_dreaming)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
typedef long long ll;
#define F first
#define S second

vector<vector<pair<int,ll>>> adj;
vector<pair<ll,ll>> dp1,dp2,path;
vector<int> pt,used;

void dfs1(int v,int e){
    used[v]=1;
    pt.push_back(v);
    for(auto &u:adj[v]){
        if(u.F==e)continue;
        dfs1(u.F,v);
        ll val=dp1[u.F].F+u.S;
        if(val>=dp1[v].F){
            dp2[v]=dp1[v];
            dp1[v]={val,u.F};
        }else if(val>=dp2[v].F){
            dp2[v]={val,u.F};
        }
    }
}

void dfs2(int v,int e){
    for(auto &u:adj[v]){
        if(u.F==e)continue;
        ll val;
        if(u.F==dp1[v].S)val=dp2[v].F+u.S;
        else val=dp1[v].F+u.S;
        if(val>=dp1[u.F].F){
            dp2[u.F]=dp1[u.F];
            dp1[u.F]={val,v};
        }else if(val>=dp2[u.F].F){
            dp2[u.F]={val,v};
        }
        dfs2(u.F,v);
    }
}

void init(ll pos){
    pt.clear();
    dfs1(pos,-1);
    dfs2(pos,-1);
    ll mx=0;
    for(auto v:pt){
        mx=max(mx,dp1[v].F+dp2[v].F);
    }
    int idx=-1;
    ll mn=LLONG_MAX;
    for(auto v:pt){
        ll val=dp1[v].F+dp2[v].F;
        if(val==mx){
            ll x=max(dp1[v].F,dp2[v].F);
            if(x<mn){
                mn=x;
                idx=v;
            }
        }
    }
    path.push_back({mn,idx});
}

ll travelTime(int N,int M,int L,int a[],int b[],int t[]){
    adj.assign(N,vector<pair<ll,ll>>());
    dp1.assign(N,{0,-1});
    dp2.assign(N,{0,-1});
    used.assign(N,0);
    path.clear();
    for(int i=0;i<M;i++){
        int x=a[i],y=b[i];
        ll z=t[i];
        adj[x].push_back({y,z});
        adj[y].push_back({x,z});
    }
    for(int i=0;i<N;i++){
        if(!used[i])init(i);
    }
    sort(path.begin(),path.end(),greater<pair<ll,int>>());
    for(int i=1;i<path.size();i++){
        int x=path[i].S,y=path[0].S;
        adj[x].push_back({y,(ll)L});
        adj[y].push_back({x,(ll)L});
    }
    for(int i=0;i<N;i++){
        dp1[i]=dp2[i]={0,-1};
    }
    pt.clear();
    dfs1(0,-1);
    dfs2(0,-1);
    ll mx=0;
    for(int i=0;i<N;i++) mx=max(mx,dp1[i].F);

    return mx;
}

Compilation message (stderr)

dreaming.cpp:67:4: error: ambiguating new declaration of 'll travelTime(int, int, int, int*, int*, int*)'
   67 | ll travelTime(int N,int M,int L,int a[],int b[],int t[]){
      |    ^~~~~~~~~~
In file included from dreaming.cpp:2:
dreaming.h:8:5: note: old declaration 'int travelTime(int, int, int, int*, int*, int*)'
    8 | int travelTime(int N, int M, int L, int A[], int B[], int T[]);
      |     ^~~~~~~~~~
dreaming.cpp: In function 'll travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:68:15: error: no matching function for call to 'std::vector<std::vector<std::pair<int, long long int> > >::assign(int&, std::vector<std::pair<long long int, long long int> >)'
   68 |     adj.assign(N,vector<pair<ll,ll>>());
      |     ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53,
                 from dreaming.cpp:1:
/usr/include/c++/13/bits/stl_vector.h:828:9: note: candidate: 'template<class _InputIterator, class> constexpr void std::vector<_Tp, _Alloc>::assign(_InputIterator, _InputIterator) [with <template-parameter-2-2> = _InputIterator; _Tp = std::vector<std::pair<int, long long int> >; _Alloc = std::allocator<std::vector<std::pair<int, long long int> > >]'
  828 |         assign(_InputIterator __first, _InputIterator __last)
      |         ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:828:9: note:   template argument deduction/substitution failed:
dreaming.cpp:68:15: note:   deduced conflicting types for parameter '_InputIterator' ('int' and 'std::vector<std::pair<long long int, long long int> >')
   68 |     adj.assign(N,vector<pair<ll,ll>>());
      |     ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:808:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::assign(size_type, const value_type&) [with _Tp = std::vector<std::pair<int, long long int> >; _Alloc = std::allocator<std::vector<std::pair<int, long long int> > >; size_type = long unsigned int; value_type = std::vector<std::pair<int, long long int> >]'
  808 |       assign(size_type __n, const value_type& __val)
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:808:47: note:   no known conversion for argument 2 from 'std::vector<std::pair<long long int, long long int> >' to 'const std::vector<std::vector<std::pair<int, long long int> > >::value_type&' {aka 'const std::vector<std::pair<int, long long int> >&'}
  808 |       assign(size_type __n, const value_type& __val)
      |                             ~~~~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/13/bits/stl_vector.h:855:7: note: candidate: 'constexpr void std::vector<_Tp, _Alloc>::assign(std::initializer_list<_Tp>) [with _Tp = std::vector<std::pair<int, long long int> >; _Alloc = std::allocator<std::vector<std::pair<int, long long int> > >]'
  855 |       assign(initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/13/bits/stl_vector.h:855:7: note:   candidate expects 1 argument, 2 provided