Submission #537866

# Submission time Handle Problem Language Result Execution time Memory
537866 2022-03-15T17:52:51 Z timreizin Dreaming (IOI13_dreaming) C++17
18 / 100
1000 ms 11148 KB
#include "dreaming.h"
#include <vector>
#include <algorithm>

using namespace std;

pair<int, int> furthest(int v, int p, vector<bool> &used, vector<vector<pair<int, int>>> &adj)
{
    used[v] = true;
    pair<int, int> res = {v, 0};
    for (auto [u, w] : adj[v])
    {
        if (u == p) continue;
        pair<int, int> ret = furthest(u, v, used, adj);
        ret.second += w;
        if (ret.second > res.second) res = ret;
    }
    return res;
}

bool findPath(int v, int p, int e, vector<vector<pair<int, int>>> &adj, vector<int> &path)
{
    if (v == e) return true;
    for (auto [u, w] : adj[v])
    {
        if (u == p) continue;
        bool ret = findPath(u, v, e, adj, path);
        if (ret)
        {
            path.push_back(w);
            return true;
        }
    }
    return false;
}

void dfs(int v, int p, vector<vector<pair<int, int>>> &adj, vector<int> &vertices, vector<bool> &used)
{
    used[v] = true;
    vertices.push_back(v);
    for (auto [u, w] : adj[v]) if (u != p) dfs(u, v, adj, vertices, used);
}

int dfs2(int v, int p, vector<vector<pair<int, int>>> &adj)
{
    int maxd = 0;
    for (auto [u, w] : adj[v])
    {
        if (u == p) continue;
        int d = dfs2(u, v, adj);
        maxd = max(maxd, d + w);
    }
    return maxd;
}

int travelTime(int n, int m, int l, int A[], int B[], int T[])
{
    vector<vector<pair<int, int>>> adj(n);
    for (int i = 0; i < m; ++i)
    {
        adj[A[i]].emplace_back(B[i], T[i]);
        adj[B[i]].emplace_back(A[i], T[i]);
    }
    vector<bool> used(n);
    vector<int> weights;
    for (int i = 0; i < n; ++i)
    {
        if (!used[i])
        {
            vector<int> vertices;
            dfs(i, -1, adj, vertices, used);
            int minD = 1e9;
            for (int j : vertices) minD = min(minD, dfs2(j, -1, adj));
            weights.push_back(minD);
            /*int a = furthest(i, -1, used, adj).first;
            int b = furthest(a, -1, used, adj).first;
            if (a == b)
            {
                weights.push_back(0);
                continue;
            }
            vector<int> path;
            findPath(a, -1, b, adj, path);
            int minRes = 1e9 + 1, suff = 0, pref = 0;
            for (int j = (int)path.size() - 1; j >= 0; --j) suff += path[j];
            for (int j = 0; j < path.size(); ++j)
            {
                minRes = min(minRes, max(suff, pref));
                pref += path[j];
                suff -= path[j];
            }
            weights.push_back(minRes);*/
        }
    }
    sort(weights.begin(), weights.end(), greater<>());
    if (weights.size() == 1) return weights[0];
    if (weights.size() == 2) return weights[0] + weights[1] + l;
    return max(weights[0] + weights[1] + l, weights[1] + weights[2] + 2 * l);
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1089 ms 11148 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1089 ms 11148 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 5400 KB Output is correct
2 Correct 21 ms 5356 KB Output is correct
3 Correct 25 ms 5380 KB Output is correct
4 Correct 25 ms 5416 KB Output is correct
5 Correct 28 ms 5380 KB Output is correct
6 Correct 36 ms 5904 KB Output is correct
7 Correct 22 ms 5592 KB Output is correct
8 Correct 21 ms 5340 KB Output is correct
9 Correct 20 ms 5204 KB Output is correct
10 Correct 22 ms 5604 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 6 ms 3236 KB Output is correct
13 Correct 9 ms 3280 KB Output is correct
14 Correct 7 ms 3280 KB Output is correct
15 Correct 9 ms 3280 KB Output is correct
16 Correct 8 ms 3280 KB Output is correct
17 Correct 7 ms 3280 KB Output is correct
18 Correct 6 ms 3376 KB Output is correct
19 Correct 6 ms 3280 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 6 ms 3280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1089 ms 11148 KB Time limit exceeded
2 Halted 0 ms 0 KB -