Submission #900566

# Submission time Handle Problem Language Result Execution time Memory
900566 2024-01-08T14:38:33 Z JakobZorz Dreaming (IOI13_dreaming) C++17
Compilation error
0 ms 0 KB
#include"dreaming.h"
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;

vector<pair<ll,ll>>nodes[100000];
bool vis[100000];
vector<ll>node_list;

void dfs(ll node){
    if(vis[node])
        return;
    vis[node]=true;
    node_list.push_back(node);
    for(auto ne:nodes[node])
        dfs(ne.first);
}

map<pair<ll,ll>,ll>dp;
ll get_max_dist(ll node,ll prev){
    if(dp.count({node,prev}))
        return dp[{node,prev}];
    
    ll res=0;
    for(auto ne:nodes[node]){
        if(ne.first==prev)
            continue;
        res=max(res,get_max_dist(ne.first,node)+ne.second);
    }
    dp[{node,prev}]=res;
    return res;
}

ll get_diameter(ll root){
    node_list.clear();
    dfs(root);
    /*cout<<"- ";
    for(int i:node_list)
        cout<<i<<" ";
    cout<<"\n";*/
    
    ll res=1e18;
    for(ll node:node_list){
        //cout<<node<<": "<<get_max_dist(node,node)<<"\n";
        res=min(res,get_max_dist(node,node));
    }
    return res;
}

int travelTime(int N,int M,int L,int A[],int B[],int T[]){
    vector<ll>dists;
    for(int i=0;i<M;i++)
        dists.push_back(T[i]);
    sort(dists.begin(),dists.end());
    reverse(dists.begin(),dists.end());
    if(dists.size()==1)
        return dists[0];
    else
        return dists[0]+dists[1]+L;
    
    for(ll i=0;i<M;i++){
        nodes[A[i]].emplace_back(B[i],T[i]);
        nodes[B[i]].emplace_back(A[i],T[i]);
    }
    
    vector<ll>dists;
    for(ll i=0;i<N;i++)
        if(!vis[i])
            dists.push_back(get_diameter(i));
    
    /*for(int i:dists)
        cout<<i<<" ";
    cout<<"\n";*/
    
    sort(dists.begin(),dists.end());
    reverse(dists.begin(),dists.end());
    if(dists.size()==1)
        return dists[0];
    else
        return dists[0]+dists[1]+L;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:69:15: error: redeclaration of 'std::vector<long long int> dists'
   69 |     vector<ll>dists;
      |               ^~~~~
dreaming.cpp:54:15: note: 'std::vector<long long int> dists' previously declared here
   54 |     vector<ll>dists;
      |               ^~~~~