Submission #1014091

# Submission time Handle Problem Language Result Execution time Memory
1014091 2024-07-04T10:39:13 Z ZanP Dreaming (IOI13_dreaming) C++17
18 / 100
56 ms 38736 KB
#include "dreaming.h"

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;
const int mxN = 1e6;
const ll INF = 1e15;
ll n, m, l;

int travelTime(int N, int M, int L, int A[], int B[], int T[]);

vector<pair<ll, ll>> pov[mxN];
ll td[mxN];
bool vis[mxN];
ll maxd = 0, cnt = 0;
pair<ll, ll> dfs(ll u, ll par) {
    pair<ll, ll> ans = { 0,u };
    vis[u] = true;
    for (auto p : pov[u]) {
        ll v = p.first;
        ll c = p.second;
        if (v != par) {
            pair<ll, ll> q = dfs(v, u);
            q.first += c;
            ans = max(ans, q);
        }
    }
    return ans;
}

ll opt = INF;
ll opt_dfs(ll u, ll tar, ll d, ll par)
{
    if (u == tar) {
        opt = d;
        return d;
    }
    ll ans = INF;
    for (auto p : pov[u]) {
        ll v = p.first;
        ll c = p.second;
        if (v != par) {
            ll dis = opt_dfs(v, tar, d, u) - c;
            ans = min(ans, dis);
        }
    }
    opt = min(max(ans,d-ans), opt);
    return ans;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    ll n = N; ll m = M; ll l = L;
    for (ll i = 0; i < m; i++) {
        ll a = A[i], b = B[i], c = T[i];
        pov[a].push_back({ b,c });
        pov[b].push_back({ a,c });
    }
    memset(vis, 0, n);
    for (ll i = 0; i < n; i++) {
        if (!vis[i] && pov[i].size() <= 1) {
            pair<ll, ll> p = dfs(i, -1);
            pair<ll, ll> q = dfs(p.second, -1);
            maxd = q.first;
            opt = INF;
            opt_dfs(p.second, q.second, q.first, -1);
            td[cnt] = -opt;
            cnt++;
        }
    }
    if (cnt == 1) {
        return maxd;
    }
    sort(td, td + cnt);
    ll ans = l - td[0] - td[1];
    if (cnt > 2) { ans = max(ans, 2 * l - td[1] - td[2]); }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 38736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 25552 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 38736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 28856 KB Output is correct
2 Correct 30 ms 28916 KB Output is correct
3 Correct 23 ms 28764 KB Output is correct
4 Correct 25 ms 28872 KB Output is correct
5 Correct 19 ms 28772 KB Output is correct
6 Correct 20 ms 29016 KB Output is correct
7 Correct 22 ms 29020 KB Output is correct
8 Correct 20 ms 28764 KB Output is correct
9 Correct 27 ms 28552 KB Output is correct
10 Correct 19 ms 28764 KB Output is correct
11 Correct 6 ms 25436 KB Output is correct
12 Correct 8 ms 26196 KB Output is correct
13 Correct 11 ms 26460 KB Output is correct
14 Correct 7 ms 26200 KB Output is correct
15 Correct 7 ms 26320 KB Output is correct
16 Correct 8 ms 26204 KB Output is correct
17 Correct 7 ms 26204 KB Output is correct
18 Correct 8 ms 26416 KB Output is correct
19 Correct 7 ms 26204 KB Output is correct
20 Correct 5 ms 25436 KB Output is correct
21 Correct 6 ms 25432 KB Output is correct
22 Correct 7 ms 25436 KB Output is correct
23 Correct 7 ms 26332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 25552 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 38736 KB Output isn't correct
2 Halted 0 ms 0 KB -