Submission #650298

# Submission time Handle Problem Language Result Execution time Memory
650298 2022-10-13T12:40:31 Z ojoConmigo Dreaming (IOI13_dreaming) C++17
Compilation error
0 ms 0 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;

vector<vector<pair<int,int>>> g;
vector<bool> vis;
vector<int> fir,sec,ans;

void dfs1(int nodo, int p,vector<int> & comp){
    vis[nodo] = true;
    comp.push_back(nodo);
    for(auto k : g[nodo]){
        int v = k.first;
        int w = k.second;
        if(v == p)continue;
        dfs1(v,nodo,comp);
        if(fir[v] + w > fir[nodo]){
            sec[nodo] = fir[nodo];
            fir[nodo] = fir[v] + w;
        }else if(fir[v] + w > sec[nodo]){
            sec[nodo] = fir[v] + w;
        }
    }
}

int dfs2(int nodo, int p, int top){
    ans[nodo] = max(fir[nodo],top);
    for(auto k : g[nodo]){
        int v = k.first;
        int w = k.second;
        if(v == p)continue;
        if(fir[v] + w == fir[nodo]) dfs2(v,nodo,max(top,sec[nodo]) + w);
        else dfs2(v,nodo,ans[nodo] + w);
    }
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    g.resize(N);
    for(int i=0; i<M; i++){
        int x = A[i];
        int y = B[i];
        int w = T[i];
        g[x].push_back({y,w});
        g[y].push_back({x,w});
    }
    vis.assign(N,false);
    fir.assign(N,0);
    sec.assign(N,0);
    ans.resize(N);
    int m1,m2,m3;
    m1 = m2 = m3 = 0;
    for(int i=0; i<N; i++){
        if(vis[i] == false){
            vector<int> comp;
            dfs1(i,-1,comp);
            dfs2(i,-1,0);
            int q = 1e9;
            for(int x : comp){
                q = min(q,ans[x]);
            }
            if(q > m1){
                m3 = m2;
                m2 = m1;
                m1 = q;
            }else if(q > m2){
                m3 = m2;
                m2 = q;
            }else if(q > m3){
                m3 = q;
            }
            //cout << i << " " << q << endl;
        }
    }
    return max(m1+m2+L,m2+m3+2*L);
}

int main(){
    int n,m,l;
    cin >> n >> m >> l;
    int a[m],b[m],t[m];
    for(int i=0; i<m; i++){
        cin >> a[i] >> b[i] >> t[i];
    }
    cout << travelTime(n,m,l,a,b,t) << endl;
}

Compilation message

dreaming.cpp: In function 'int dfs2(int, int, int)':
dreaming.cpp:35:1: warning: no return statement in function returning non-void [-Wreturn-type]
   35 | }
      | ^
/usr/bin/ld: /tmp/ccJewxVN.o: in function `main':
dreaming.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cclrQhQO.o:grader.c:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status