Submission #414873

# Submission time Handle Problem Language Result Execution time Memory
414873 2021-05-31T09:53:12 Z snasibov05 Dreaming (IOI13_dreaming) C++14
0 / 100
1000 ms 9288 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> 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(int)':
dreaming.cpp:18:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   18 |     for (auto [x, t] : ed[v]){
      |               ^
dreaming.cpp: In function 'int mxdist(int, int)':
dreaming.cpp:25:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   25 |     for (auto [x, t] : ed[v]){
      |               ^
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:66:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |     for (int i = 0; i < mx.size(); ++i) {
      |                     ~~^~~~~~~~~~~
dreaming.cpp:74:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |     for (int i = 0; i < mx.size(); ++i){
      |                     ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1094 ms 9288 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1094 ms 9288 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 5216 KB Output is correct
2 Incorrect 22 ms 5140 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1094 ms 9288 KB Time limit exceeded
2 Halted 0 ms 0 KB -