Submission #414881

# Submission time Handle Problem Language Result Execution time Memory
414881 2021-05-31T09:59:37 Z snasibov05 Dreaming (IOI13_dreaming) C++14
18 / 100
1000 ms 9288 KB
#include "dreaming.h"
#include <vector>
#include <algorithm>

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);
    }

    sort(mx.rbegin(), mx.rend());

    if (mx.size() == 1) return mx[0];
    if (mx.size() == 2) return mx[0] + mx[1] + l;

    return max(mx[0] + mx[1] + l, mx[1] + mx[2] + 2*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]){
      |               ^
# Verdict Execution time Memory Grader output
1 Execution timed out 1080 ms 9288 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 1080 ms 9288 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 5200 KB Output is correct
2 Correct 27 ms 5216 KB Output is correct
3 Correct 27 ms 5640 KB Output is correct
4 Correct 23 ms 5640 KB Output is correct
5 Correct 29 ms 5580 KB Output is correct
6 Correct 30 ms 6096 KB Output is correct
7 Correct 23 ms 5852 KB Output is correct
8 Correct 26 ms 5552 KB Output is correct
9 Correct 24 ms 5472 KB Output is correct
10 Correct 28 ms 5816 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 5 ms 3272 KB Output is correct
13 Correct 6 ms 3272 KB Output is correct
14 Correct 6 ms 3272 KB Output is correct
15 Correct 6 ms 3272 KB Output is correct
16 Correct 6 ms 3272 KB Output is correct
17 Correct 6 ms 3272 KB Output is correct
18 Correct 6 ms 3272 KB Output is correct
19 Correct 6 ms 3272 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 284 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 5 ms 3272 KB Output is correct
# 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 1080 ms 9288 KB Time limit exceeded
2 Halted 0 ms 0 KB -