Submission #155845

# Submission time Handle Problem Language Result Execution time Memory
155845 2019-10-01T04:39:37 Z TAISA_ Dreaming (IOI13_dreaming) C++14
18 / 100
130 ms 25848 KB
#include "dreaming.h"
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (1 << 30) - 1;
const ll LINF = (1LL << 60) - 1LL;
vector<vector<P>> G;
vector<int> dep, dp, vis;
vector<multiset<int>> st;
void build(int i, int p, int d) {
    vis[i] = 1;
    dep[i] = d;
    dp[i] = dep[i];
    for (auto &e : G[i]) {
        if (e.first == p) {
            continue;
        }
        build(e.first, i, d + e.second);
        dp[i] = max(dp[i], dp[e.first]);
        st[i].insert(dp[e.first] - dep[i]);
    }
}
int calc(int i, int p) {
    int res = INF;
    if (st[i].size() > 0) {
        auto itr = st[i].end();
        --itr;
        res = (*itr);
    }
    for (auto &e : G[i]) {
        if (e.first == p) {
            continue;
        }
        int t = dp[e.first] - dep[i];
        st[i].erase(st[i].find(t));
        if (st[i].size() > 0) {
            auto it = st[i].end();
            --it;
            st[e.first].insert((*it) + e.second);
        } else {
            st[e.first].insert(e.second);
        }
        res = min(res, calc(e.first, i));
        st[i].insert(t);
    }
    //  cout << i << " " << res << endl;
    return res;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    if (M == N - 1) {
        return 0;
    }
    G.resize(N);
    st.resize(N);
    dep.resize(N);
    dp.resize(N);
    vis.resize(N);
    for (int i = 0; i < M; i++) {
        G[A[i]].push_back(P(B[i], T[i]));
        G[B[i]].push_back(P(A[i], T[i]));
    }
    vector<ll> s;
    for (int i = 0; i < N; i++) {
        if (!vis[i]) {
            if (G[i].size() == 0) {
                s.push_back(0);
                continue;
            }
            build(i, -1, 0);
            s.push_back(calc(i, -1));
        }
    }

    sort(all(s));
    reverse(all(s));
    ll ans = 0;
    if (s.size() > 1) {
        ans = max(ans, s[0] + s[1] + L);
    }
    if (s.size() > 2) {
        ans = max(ans, s[1] + s[2] + 2LL * L);
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 130 ms 25848 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 130 ms 25848 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 130 ms 25848 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 60 ms 13708 KB Output is correct
2 Correct 57 ms 13808 KB Output is correct
3 Correct 61 ms 13808 KB Output is correct
4 Correct 63 ms 13808 KB Output is correct
5 Correct 48 ms 13680 KB Output is correct
6 Correct 53 ms 15088 KB Output is correct
7 Correct 56 ms 14444 KB Output is correct
8 Correct 54 ms 13552 KB Output is correct
9 Correct 47 ms 13424 KB Output is correct
10 Correct 63 ms 14292 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 15 ms 9704 KB Output is correct
13 Correct 15 ms 9712 KB Output is correct
14 Correct 13 ms 9728 KB Output is correct
15 Correct 15 ms 9712 KB Output is correct
16 Correct 13 ms 9712 KB Output is correct
17 Correct 12 ms 9712 KB Output is correct
18 Correct 13 ms 9712 KB Output is correct
19 Correct 13 ms 9712 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 3 ms 632 KB Output is correct
23 Correct 13 ms 9712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 130 ms 25848 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 130 ms 25848 KB Output isn't correct
2 Halted 0 ms 0 KB -