Submission #889002

# Submission time Handle Problem Language Result Execution time Memory
889002 2023-12-18T15:07:21 Z dwuy Dreaming (IOI13_dreaming) C++14
47 / 100
50 ms 19580 KB
/// dwuy: _,\,,,_\,__,\,,_
#include "dreaming.h"
#include <bits/stdc++.h>

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define file(a) freopen(a".inp","r",stdin); freopen(a".out", "w",stdout)
#define fi first
#define se second
#define endl "\n"
#define len(s) int32_t(s.length())
#define MASK(k)(1LL<<(k))
#define TASK ""

using namespace std;

typedef tuple<int, int, int> tpiii;
typedef pair<double, double> pdd;
typedef pair<int, int> pii;
typedef long long ll;

const long long OO = 1e18;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MX = 100005;

struct DSU{
    int n;
    vector<int> e;

    DSU(int n=0){
        this->n = n;
        this->e.assign(n+5, -1);
    }

    int fp(int u){
        return e[u]<0? u : e[u] = fp(e[u]);
    }

    void unon(int u, int v){
        u = fp(u);
        v = fp(v);
        if(u == v) return;
        if(e[u] > e[v]) swap(u, v);
        e[u] += e[v];
        e[v] = u;
    }
};

int n, m, l;
vector<pii> G[MX];
int dp[MX];
int dpDown[MX];
int mnPath[MX];
pii pf[MX];
pii sf[MX];
DSU dsu;

void calc_dp_down(int u, int p){
    dpDown[u] = 0;
    for(pii &tmp: G[u]){
        int v, c; tie(v, c) = tmp;
        if(v == p) continue;
        calc_dp_down(v, u);
        dpDown[u] = max(dpDown[u], dpDown[v] + c);
    }
}

void calc_dp(int u, int p, int mx){
    pii best1 = {mx, p};
    pii best2 = {0, 0};
    for(pii &tmp: G[u]){
        int v, c; tie(v, c) = tmp;
        if(v == p) continue;
        int dis = dpDown[v] + c;
        if(dis >= best1.fi){
            best2 = best1;
            best1 = {dis, v};
        }
        else best2 = max(best2, {dis, v});
    }
    dp[u] = best1.fi;
    for(pii &tmp: G[u]){
        int v, c; tie(v, c) = tmp;
        if(v == p) continue;
        if(v == best1.se) calc_dp(v, u, best2.fi + c);
        else calc_dp(v, u, best1.fi + c);
    }
}

pii combine(pii a, pii b){
    if(a.fi < b.fi) swap(a, b);
    if(a.se > b.fi) return a;
    return {a.fi, b.fi};
}

int travelTime(int N, int M, int L, int A[], int B[], int C[]){
    tie(n, m, l) = {N, M, L};
    dsu = DSU(n);
    for(int i=0; i<m; i++){
        int u = A[i]; u++;
        int v = B[i]; v++;
        int c = C[i];
        G[u].push_back({v, c});
        G[v].push_back({u, c});
        dsu.unon(u, v);
    }
    memset(dpDown, -1, sizeof dpDown);
    memset(dp, -1, sizeof dp);
    for(int i=1; i<=n; i++) if(dpDown[i] == -1) calc_dp_down(i, 0);
    for(int i=1; i<=n; i++) if(dp[i] == -1) calc_dp(i, 0, 0);

    for(int i=0; i<=n+1; i++){
        pf[i] = {-1, -1};
        sf[i] = {-1, -1};
    }

    memset(mnPath, 0x3f, sizeof mnPath);
    for(int i=1; i<=n; i++){
        int root = dsu.fp(i);
        mnPath[root] = min(mnPath[root], dp[i]);
    }
    for(int i=1;  i<=n; i++) if(dsu.fp(i) != i) mnPath[i] = -1;

    for(int i=1; i<=n; i++){
        pf[i] = {mnPath[i], -1};
        pf[i] = combine(pf[i-1], pf[i]);
    }
    for(int i=n; i>=1; i--){
        if(dsu.fp(i) == i) sf[i] = {mnPath[i], -1};
        else sf[i] = {-1, -1};
        sf[i] = combine(sf[i+1], sf[i]);
    }
    int ans = INF;
    for(int i=1; i<=n; i++) if(dsu.fp(i) == i){
        pii best = combine(pf[i-1], sf[i+1]);
        if(best.fi != -1 && best.se != -1) ans = min(ans, best.fi + best.se + l + l);
        ans = min(ans, best.fi + mnPath[i] + l);
    }
    for(int i=1; i<=n; i++) ans = max(ans, dp[i]);
    return ans;
}


# Verdict Execution time Memory Grader output
1 Correct 31 ms 13652 KB Output is correct
2 Correct 32 ms 13392 KB Output is correct
3 Correct 23 ms 12636 KB Output is correct
4 Correct 7 ms 7516 KB Output is correct
5 Correct 5 ms 7004 KB Output is correct
6 Correct 9 ms 8028 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 17 ms 10076 KB Output is correct
9 Correct 22 ms 12124 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 30 ms 12812 KB Output is correct
12 Correct 33 ms 13648 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 2 ms 6528 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6528 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 2 ms 6492 KB Output is correct
25 Correct 2 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 13652 KB Output is correct
2 Correct 32 ms 13392 KB Output is correct
3 Correct 23 ms 12636 KB Output is correct
4 Correct 7 ms 7516 KB Output is correct
5 Correct 5 ms 7004 KB Output is correct
6 Correct 9 ms 8028 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 17 ms 10076 KB Output is correct
9 Correct 22 ms 12124 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 30 ms 12812 KB Output is correct
12 Correct 33 ms 13648 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 2 ms 6492 KB Output is correct
25 Correct 2 ms 6492 KB Output is correct
26 Correct 2 ms 6492 KB Output is correct
27 Correct 2 ms 6492 KB Output is correct
28 Correct 2 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 2 ms 6492 KB Output is correct
31 Correct 2 ms 6492 KB Output is correct
32 Correct 2 ms 6528 KB Output is correct
33 Correct 2 ms 6492 KB Output is correct
34 Correct 2 ms 6528 KB Output is correct
35 Correct 2 ms 6492 KB Output is correct
36 Correct 2 ms 6492 KB Output is correct
37 Correct 2 ms 6492 KB Output is correct
38 Correct 2 ms 6492 KB Output is correct
39 Correct 35 ms 15012 KB Output is correct
40 Correct 31 ms 14684 KB Output is correct
41 Correct 24 ms 13660 KB Output is correct
42 Correct 6 ms 7772 KB Output is correct
43 Correct 3 ms 6588 KB Output is correct
44 Correct 2 ms 6692 KB Output is correct
45 Correct 2 ms 6492 KB Output is correct
46 Correct 2 ms 6500 KB Output is correct
47 Correct 2 ms 6488 KB Output is correct
48 Correct 2 ms 6488 KB Output is correct
49 Correct 2 ms 6492 KB Output is correct
50 Correct 2 ms 6408 KB Output is correct
51 Correct 2 ms 6492 KB Output is correct
52 Correct 2 ms 6352 KB Output is correct
53 Correct 2 ms 6492 KB Output is correct
54 Correct 2 ms 6492 KB Output is correct
55 Correct 2 ms 6492 KB Output is correct
56 Correct 2 ms 6488 KB Output is correct
57 Correct 44 ms 12376 KB Output is correct
58 Correct 42 ms 12300 KB Output is correct
59 Correct 39 ms 12116 KB Output is correct
60 Correct 40 ms 12116 KB Output is correct
61 Correct 39 ms 12368 KB Output is correct
62 Correct 40 ms 12448 KB Output is correct
63 Correct 43 ms 12028 KB Output is correct
64 Correct 38 ms 11860 KB Output is correct
65 Correct 39 ms 12164 KB Output is correct
66 Correct 37 ms 12372 KB Output is correct
67 Correct 40 ms 12128 KB Output is correct
68 Correct 40 ms 12380 KB Output is correct
69 Correct 42 ms 12456 KB Output is correct
70 Correct 50 ms 12624 KB Output is correct
71 Correct 1 ms 6492 KB Output is correct
72 Correct 3 ms 6492 KB Output is correct
73 Correct 3 ms 6540 KB Output is correct
74 Correct 3 ms 6492 KB Output is correct
75 Correct 3 ms 6576 KB Output is correct
76 Correct 3 ms 6568 KB Output is correct
77 Correct 2 ms 6492 KB Output is correct
78 Correct 2 ms 6492 KB Output is correct
79 Correct 3 ms 6572 KB Output is correct
80 Correct 42 ms 12148 KB Output is correct
81 Correct 44 ms 12200 KB Output is correct
82 Correct 40 ms 12368 KB Output is correct
83 Correct 39 ms 12276 KB Output is correct
84 Correct 2 ms 6488 KB Output is correct
85 Correct 2 ms 6492 KB Output is correct
86 Correct 2 ms 6492 KB Output is correct
87 Correct 2 ms 6492 KB Output is correct
88 Correct 2 ms 6492 KB Output is correct
89 Correct 2 ms 6492 KB Output is correct
90 Correct 2 ms 6492 KB Output is correct
91 Correct 3 ms 6744 KB Output is correct
92 Correct 3 ms 6688 KB Output is correct
93 Correct 2 ms 6492 KB Output is correct
94 Correct 2 ms 6492 KB Output is correct
95 Correct 2 ms 6492 KB Output is correct
96 Correct 2 ms 6492 KB Output is correct
97 Correct 2 ms 6532 KB Output is correct
98 Correct 2 ms 6492 KB Output is correct
99 Correct 2 ms 6492 KB Output is correct
100 Correct 2 ms 6492 KB Output is correct
101 Correct 2 ms 6520 KB Output is correct
102 Correct 2 ms 6492 KB Output is correct
103 Correct 2 ms 6744 KB Output is correct
104 Correct 5 ms 7260 KB Output is correct
105 Correct 9 ms 8284 KB Output is correct
106 Correct 2 ms 6492 KB Output is correct
107 Correct 23 ms 9944 KB Output is correct
108 Correct 22 ms 12120 KB Output is correct
109 Correct 2 ms 6492 KB Output is correct
110 Correct 31 ms 12892 KB Output is correct
111 Correct 35 ms 13620 KB Output is correct
112 Correct 2 ms 6488 KB Output is correct
113 Correct 47 ms 19580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 8792 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 2 ms 6528 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6528 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 2 ms 6492 KB Output is correct
25 Correct 2 ms 6492 KB Output is correct
26 Correct 2 ms 6492 KB Output is correct
27 Correct 2 ms 6492 KB Output is correct
28 Correct 3 ms 6536 KB Output is correct
29 Incorrect 2 ms 6492 KB Output isn't correct
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 13652 KB Output is correct
2 Correct 32 ms 13392 KB Output is correct
3 Correct 23 ms 12636 KB Output is correct
4 Correct 7 ms 7516 KB Output is correct
5 Correct 5 ms 7004 KB Output is correct
6 Correct 9 ms 8028 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 17 ms 10076 KB Output is correct
9 Correct 22 ms 12124 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 30 ms 12812 KB Output is correct
12 Correct 33 ms 13648 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 2 ms 6492 KB Output is correct
24 Correct 2 ms 6492 KB Output is correct
25 Correct 2 ms 6492 KB Output is correct
26 Correct 2 ms 6492 KB Output is correct
27 Correct 2 ms 6492 KB Output is correct
28 Correct 2 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 2 ms 6492 KB Output is correct
31 Correct 2 ms 6492 KB Output is correct
32 Correct 2 ms 6528 KB Output is correct
33 Correct 2 ms 6492 KB Output is correct
34 Correct 2 ms 6528 KB Output is correct
35 Correct 2 ms 6492 KB Output is correct
36 Correct 2 ms 6492 KB Output is correct
37 Correct 2 ms 6492 KB Output is correct
38 Correct 2 ms 6492 KB Output is correct
39 Correct 35 ms 15012 KB Output is correct
40 Correct 31 ms 14684 KB Output is correct
41 Correct 24 ms 13660 KB Output is correct
42 Correct 6 ms 7772 KB Output is correct
43 Correct 3 ms 6588 KB Output is correct
44 Correct 2 ms 6692 KB Output is correct
45 Correct 2 ms 6492 KB Output is correct
46 Correct 2 ms 6500 KB Output is correct
47 Correct 2 ms 6488 KB Output is correct
48 Correct 2 ms 6488 KB Output is correct
49 Correct 2 ms 6492 KB Output is correct
50 Correct 2 ms 6408 KB Output is correct
51 Correct 2 ms 6492 KB Output is correct
52 Correct 2 ms 6352 KB Output is correct
53 Correct 2 ms 6492 KB Output is correct
54 Correct 2 ms 6492 KB Output is correct
55 Correct 2 ms 6492 KB Output is correct
56 Correct 2 ms 6488 KB Output is correct
57 Correct 44 ms 12376 KB Output is correct
58 Correct 42 ms 12300 KB Output is correct
59 Correct 39 ms 12116 KB Output is correct
60 Correct 40 ms 12116 KB Output is correct
61 Correct 39 ms 12368 KB Output is correct
62 Correct 40 ms 12448 KB Output is correct
63 Correct 43 ms 12028 KB Output is correct
64 Correct 38 ms 11860 KB Output is correct
65 Correct 39 ms 12164 KB Output is correct
66 Correct 37 ms 12372 KB Output is correct
67 Correct 40 ms 12128 KB Output is correct
68 Correct 40 ms 12380 KB Output is correct
69 Correct 42 ms 12456 KB Output is correct
70 Correct 50 ms 12624 KB Output is correct
71 Correct 1 ms 6492 KB Output is correct
72 Correct 3 ms 6492 KB Output is correct
73 Correct 3 ms 6540 KB Output is correct
74 Correct 3 ms 6492 KB Output is correct
75 Correct 3 ms 6576 KB Output is correct
76 Correct 3 ms 6568 KB Output is correct
77 Correct 2 ms 6492 KB Output is correct
78 Correct 2 ms 6492 KB Output is correct
79 Correct 3 ms 6572 KB Output is correct
80 Correct 42 ms 12148 KB Output is correct
81 Correct 44 ms 12200 KB Output is correct
82 Correct 40 ms 12368 KB Output is correct
83 Correct 39 ms 12276 KB Output is correct
84 Correct 2 ms 6488 KB Output is correct
85 Correct 2 ms 6492 KB Output is correct
86 Correct 2 ms 6492 KB Output is correct
87 Correct 2 ms 6492 KB Output is correct
88 Correct 2 ms 6492 KB Output is correct
89 Correct 2 ms 6492 KB Output is correct
90 Correct 2 ms 6492 KB Output is correct
91 Correct 3 ms 6744 KB Output is correct
92 Correct 3 ms 6688 KB Output is correct
93 Correct 2 ms 6492 KB Output is correct
94 Correct 2 ms 6492 KB Output is correct
95 Correct 2 ms 6492 KB Output is correct
96 Correct 2 ms 6492 KB Output is correct
97 Correct 2 ms 6532 KB Output is correct
98 Correct 2 ms 6492 KB Output is correct
99 Correct 2 ms 6492 KB Output is correct
100 Correct 2 ms 6492 KB Output is correct
101 Correct 2 ms 6520 KB Output is correct
102 Correct 2 ms 6492 KB Output is correct
103 Correct 2 ms 6744 KB Output is correct
104 Correct 5 ms 7260 KB Output is correct
105 Correct 9 ms 8284 KB Output is correct
106 Correct 2 ms 6492 KB Output is correct
107 Correct 23 ms 9944 KB Output is correct
108 Correct 22 ms 12120 KB Output is correct
109 Correct 2 ms 6492 KB Output is correct
110 Correct 31 ms 12892 KB Output is correct
111 Correct 35 ms 13620 KB Output is correct
112 Correct 2 ms 6488 KB Output is correct
113 Correct 47 ms 19580 KB Output is correct
114 Incorrect 15 ms 8792 KB Output isn't correct
115 Halted 0 ms 0 KB -