Submission #345550

# Submission time Handle Problem Language Result Execution time Memory
345550 2021-01-07T14:48:58 Z 79brue Dreaming (IOI13_dreaming) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, m, k;
vector<pair<int, int> > link[100002];
int DP[100002], DP2[100002];
bool visited[100002];
int ans;

int minVal;
vector<int> vec;

void dfs(int x){
    visited[x] = 1;
    for(auto y: link[x]){
        if(visited[y.first]) continue;
        dfs(y.first);

        int tmp1 = DP[y.first] + y.second;
        int tmp2 = DP2[y.first] + y.second;
        if(DP2[x] < tmp1) DP2[x] = tmp1;
        if(DP2[x] > DP[x]) swap(DP[x], DP2[x]);
        if(DP2[x] < tmp2) DP2[x] = tmp2;
    }
    if(DP[x] < 0) DP[x] = 0;
    ans = max(ans, DP[x] + DP2[x]);
    visited[x] = 0;
}
void dfs2(int x, int fromUp){
    visited[x] = 1;
    minVal = min(minVal, max(fromUp, DP[x]));
    for(auto y: link[x]){
        if(visited[y.first]) continue;
        dfs2(y.first, max(fromUp, (DP[x] == DP[y.first] + y.second) ? DP2[x] : DP[x]) + y.second);
    }
}

int travelTime(int _n, int _m, int _k, int x[], int y[], int z[]){
    n = _n, m = _m, k = _k;
    for(int i=0; i<n; i++) DP[i] = DP2[i] = -1e9;
    for(int i=0; i<m; i++){
        link[x[i]].push_back(make_pair(y[i], z[i]));
        link[y[i]].push_back(make_pair(x[i], z[i]));
    }

    for(int i=0; i<n; i++){
        if(!visited[i]){
            minVal = INT_MAX;
            dfs(i);
            dfs2(i, 0);
            vec.push_back(minVal);
        }
    }
    sort(vec.rbegin(), vec.rend());
    if(vec.size() >= 2) ans = max(ans, vec[0] + k + vec[1]);
    if(vec.size() >= 3) ans = max(ans, vec[1] + k + k + vec[2]);
    return ans;
}

Compilation message

/tmp/ccV8i3gd.o: In function `main':
grader.c:(.text.startup+0xc9): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status