Submission #414875

# Submission time Handle Problem Language Result Execution time Memory
414875 2021-05-31T09:56:00 Z snasibov05 Dreaming (IOI13_dreaming) C++14
Compilation error
0 ms 0 KB
#include "dreaming.h"
#include <vector>

using namespace std;

#define pb push_back
#define int long long
#define pii pair<int, int>
#define oo 1000000000000000000ll

vector<vector<pii>> ed;
vector<bool> visited;
vector<int> mx;
vector<int> cur;

void dfs(int v){
    cur.pb(v);
    visited[v] = true;
    for (auto [x, t] : ed[v]){
        if (!visited[x]) dfs(x);
    }
}

int mxdist(int v, int pr){
    int res = 0;
    for (auto [x, t] : ed[v]){
        if (x != pr){
            res = max(res, mxdist(x, v) + t);
        }
    }

    return res;
}

void findmn(int v){

    cur.clear();
    dfs(v);

    int mn = oo;

    for (auto x : cur){
        int k = mxdist(x, -1);
        mn = min(mn, k);
    }

    mx.pb(mn);

}

int travelTime(int n, int m, int l, int a[], int b[], int t[]) {

    ed.resize(n);
    visited.resize(n);


    for (int i = 0; i < m; ++i) {
        ed[a[i]].pb({b[i], t[i]});
        ed[b[i]].pb({a[i], t[i]});
    }

    for (int i = 0; i < n; ++i) {
        if (!visited[i]) findmn(i);
    }

    int Max = 0, Maxi = 0;
    for (int i = 0; i < mx.size(); ++i) {
        if (mx[i] > Max){
            Max = mx[i];
            Maxi = i;
        }
    }

    int SMax = 0;
    for (int i = 0; i < mx.size(); ++i){
        if (mx[i] > SMax && i != Maxi) SMax = mx[i];
    }

    return Max + SMax + l;

}

Compilation message

dreaming.cpp: In function 'void dfs(long long int)':
dreaming.cpp:19:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   19 |     for (auto [x, t] : ed[v]){
      |               ^
dreaming.cpp: In function 'long long int mxdist(long long int, long long int)':
dreaming.cpp:26:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   26 |     for (auto [x, t] : ed[v]){
      |               ^
dreaming.cpp: In function 'long long int travelTime(long long int, long long int, long long int, long long int*, long long int*, long long int*)':
dreaming.cpp:67:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for (int i = 0; i < mx.size(); ++i) {
      |                     ~~^~~~~~~~~~~
dreaming.cpp:75:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |     for (int i = 0; i < mx.size(); ++i){
      |                     ~~^~~~~~~~~~~
/usr/bin/ld: /tmp/ccGIiqy4.o: in function `main':
grader.c:(.text.startup+0xd1): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status