Submission #414870

# Submission time Handle Problem Language Result Execution time Memory
414870 2021-05-31T09:51:36 Z snasibov05 Dreaming (IOI13_dreaming) C++14
0 / 100
1000 ms 10952 KB
#include "dreaming.h"
#include <vector>

using namespace std;

#define pb push_back
#define pii pair<int, int>
#define oo 1000000000

vector<vector<pii>> ed;
vector<bool> visited;
vector<int> root;
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, rt = -1;

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

    for (auto x : cur){
        root[x] = rt;
    }

    mx.pb(mn);

}

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

    ed.resize(n);
    visited.resize(n);
    root.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(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 'int mxdist(int, 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 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:73:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |     for (int i = 0; i < mx.size(); ++i) {
      |                     ~~^~~~~~~~~~~
dreaming.cpp:81:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |     for (int i = 0; i < mx.size(); ++i){
      |                     ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1075 ms 10952 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1075 ms 10952 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 5912 KB Output is correct
2 Incorrect 23 ms 5996 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1075 ms 10952 KB Time limit exceeded
2 Halted 0 ms 0 KB -