Submission #426506

# Submission time Handle Problem Language Result Execution time Memory
426506 2021-06-14T05:44:51 Z Aldas25 Dreaming (IOI13_dreaming) C++14
47 / 100
135 ms 16304 KB
#include "dreaming.h"
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i<= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define f first
#define s second
#define pb push_back
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef long long ll;
typedef vector<ll> vl;

const int MAXN = 100100;
const ll INF = 1e15;

int n, m;
ll l;
vii adj[MAXN];

ll dp[MAXN][2];
bool vis[MAXN];

ll mx, sm;

void dfs1 (int v, int p = -1) {
    vis[v] = true;
    for (auto pp : adj[v]) {
        int u = pp.f;
        ll w = pp.s;
        if (u == p) continue;
        dfs1(u, v);

        ll cr = dp[u][0] + w;
        if (cr > dp[v][1]) dp[v][1] = cr;
        if (dp[v][1] > dp[v][0]) swap(dp[v][0], dp[v][1]);
    }

    mx = max(mx, dp[v][0]+dp[v][1]);

    //cout << " v = " << v << " dp0 = " << dp[v][0] << " dp1 = " << dp[v][1] << endl;
}

void dfs2 (int v, int p = -1, ll prevW = 0) {
    if (p != -1) {
        ll cr = 0;
        if (dp[p][0] != dp[v][0] + prevW)
            cr = dp[p][0] + prevW;
        else
            cr = dp[p][1] + prevW;

        if (cr > dp[v][1]) dp[v][1] = cr;
        if (dp[v][1] > dp[v][0]) swap(dp[v][0], dp[v][1]);
    }

    for (auto pp : adj[v]) {
        int u = pp.f;
        ll w = pp.s;
        if (u == p) continue;
        dfs2(u, v, w);
    }

    sm = min(sm, dp[v][0]);

    //cout << " dfs2 v = " << v << " dp0 = " << dp[v][0] << " dp1 = " << dp[v][1] << endl;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    n = N;
    m = M;
    l = L;

    FOR(i, 0, m-1) {
        adj[A[i]].pb({B[i], T[i]});
        adj[B[i]].pb({A[i], T[i]});
    }

    ll ans = 0;
    vl sms;
    FOR(i, 0, n-1) {
        if (vis[i]) continue;
        mx = 0;
        dfs1 (i);
        ans = max(mx, ans);

        sm = INF;
        dfs2 (i);
        sms.pb(sm);
    }

    ll cur = 0;
    if ((int)sms.size() > 1) {
        sort(sms.begin(), sms.end());
        reverse(sms.begin(), sms.end());
        cur = sms[0] + sms[1] + l;
    }

    ans = max(ans, cur);

    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 67 ms 11960 KB Output is correct
2 Correct 61 ms 11656 KB Output is correct
3 Correct 41 ms 10196 KB Output is correct
4 Correct 8 ms 3916 KB Output is correct
5 Correct 6 ms 3404 KB Output is correct
6 Correct 14 ms 4668 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 26 ms 6476 KB Output is correct
9 Correct 36 ms 8616 KB Output is correct
10 Correct 3 ms 2684 KB Output is correct
11 Correct 46 ms 9292 KB Output is correct
12 Correct 83 ms 10564 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 2 ms 2764 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 3 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 2 ms 2636 KB Output is correct
12 Correct 2 ms 2636 KB Output is correct
13 Correct 3 ms 2636 KB Output is correct
14 Correct 2 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 3 ms 2636 KB Output is correct
18 Correct 2 ms 2636 KB Output is correct
19 Correct 2 ms 2636 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 2 ms 2636 KB Output is correct
23 Correct 2 ms 2636 KB Output is correct
24 Correct 2 ms 2636 KB Output is correct
25 Correct 2 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 11960 KB Output is correct
2 Correct 61 ms 11656 KB Output is correct
3 Correct 41 ms 10196 KB Output is correct
4 Correct 8 ms 3916 KB Output is correct
5 Correct 6 ms 3404 KB Output is correct
6 Correct 14 ms 4668 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 26 ms 6476 KB Output is correct
9 Correct 36 ms 8616 KB Output is correct
10 Correct 3 ms 2684 KB Output is correct
11 Correct 46 ms 9292 KB Output is correct
12 Correct 83 ms 10564 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 3 ms 2636 KB Output is correct
15 Correct 2 ms 2764 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 3 ms 2636 KB Output is correct
18 Correct 2 ms 2636 KB Output is correct
19 Correct 2 ms 2636 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 2 ms 2636 KB Output is correct
23 Correct 2 ms 2636 KB Output is correct
24 Correct 2 ms 2636 KB Output is correct
25 Correct 2 ms 2636 KB Output is correct
26 Correct 3 ms 2636 KB Output is correct
27 Correct 2 ms 2636 KB Output is correct
28 Correct 2 ms 2636 KB Output is correct
29 Correct 2 ms 2636 KB Output is correct
30 Correct 3 ms 2636 KB Output is correct
31 Correct 2 ms 2636 KB Output is correct
32 Correct 2 ms 2636 KB Output is correct
33 Correct 2 ms 2636 KB Output is correct
34 Correct 2 ms 2636 KB Output is correct
35 Correct 2 ms 2636 KB Output is correct
36 Correct 2 ms 2636 KB Output is correct
37 Correct 2 ms 2636 KB Output is correct
38 Correct 2 ms 2636 KB Output is correct
39 Correct 73 ms 11940 KB Output is correct
40 Correct 66 ms 11664 KB Output is correct
41 Correct 41 ms 10212 KB Output is correct
42 Correct 9 ms 3928 KB Output is correct
43 Correct 2 ms 2636 KB Output is correct
44 Correct 2 ms 2636 KB Output is correct
45 Correct 2 ms 2636 KB Output is correct
46 Correct 2 ms 2636 KB Output is correct
47 Correct 2 ms 2636 KB Output is correct
48 Correct 2 ms 2636 KB Output is correct
49 Correct 2 ms 2636 KB Output is correct
50 Correct 2 ms 2636 KB Output is correct
51 Correct 2 ms 2636 KB Output is correct
52 Correct 2 ms 2636 KB Output is correct
53 Correct 2 ms 2636 KB Output is correct
54 Correct 2 ms 2636 KB Output is correct
55 Correct 2 ms 2636 KB Output is correct
56 Correct 2 ms 2636 KB Output is correct
57 Correct 103 ms 9412 KB Output is correct
58 Correct 74 ms 9412 KB Output is correct
59 Correct 81 ms 9396 KB Output is correct
60 Correct 70 ms 9316 KB Output is correct
61 Correct 74 ms 9384 KB Output is correct
62 Correct 103 ms 9248 KB Output is correct
63 Correct 74 ms 9024 KB Output is correct
64 Correct 77 ms 9140 KB Output is correct
65 Correct 74 ms 9060 KB Output is correct
66 Correct 68 ms 9140 KB Output is correct
67 Correct 80 ms 9372 KB Output is correct
68 Correct 135 ms 9404 KB Output is correct
69 Correct 116 ms 9340 KB Output is correct
70 Correct 105 ms 9380 KB Output is correct
71 Correct 3 ms 2636 KB Output is correct
72 Correct 4 ms 2764 KB Output is correct
73 Correct 4 ms 2764 KB Output is correct
74 Correct 3 ms 2764 KB Output is correct
75 Correct 4 ms 2764 KB Output is correct
76 Correct 4 ms 2764 KB Output is correct
77 Correct 5 ms 2764 KB Output is correct
78 Correct 4 ms 2764 KB Output is correct
79 Correct 4 ms 2764 KB Output is correct
80 Correct 110 ms 9348 KB Output is correct
81 Correct 105 ms 9292 KB Output is correct
82 Correct 93 ms 9304 KB Output is correct
83 Correct 88 ms 9256 KB Output is correct
84 Correct 3 ms 2816 KB Output is correct
85 Correct 3 ms 2764 KB Output is correct
86 Correct 3 ms 2764 KB Output is correct
87 Correct 3 ms 2764 KB Output is correct
88 Correct 3 ms 2764 KB Output is correct
89 Correct 4 ms 2764 KB Output is correct
90 Correct 4 ms 2764 KB Output is correct
91 Correct 5 ms 2764 KB Output is correct
92 Correct 3 ms 2764 KB Output is correct
93 Correct 3 ms 2764 KB Output is correct
94 Correct 2 ms 2636 KB Output is correct
95 Correct 2 ms 2636 KB Output is correct
96 Correct 2 ms 2648 KB Output is correct
97 Correct 2 ms 2636 KB Output is correct
98 Correct 2 ms 2636 KB Output is correct
99 Correct 2 ms 2636 KB Output is correct
100 Correct 2 ms 2636 KB Output is correct
101 Correct 2 ms 2636 KB Output is correct
102 Correct 2 ms 2636 KB Output is correct
103 Correct 2 ms 2636 KB Output is correct
104 Correct 7 ms 3404 KB Output is correct
105 Correct 13 ms 4684 KB Output is correct
106 Correct 2 ms 2636 KB Output is correct
107 Correct 26 ms 6552 KB Output is correct
108 Correct 40 ms 8652 KB Output is correct
109 Correct 2 ms 2636 KB Output is correct
110 Correct 53 ms 9404 KB Output is correct
111 Correct 72 ms 10676 KB Output is correct
112 Correct 2 ms 2636 KB Output is correct
113 Correct 95 ms 16304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 7120 KB Output is correct
2 Incorrect 30 ms 7624 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Correct 2 ms 2764 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 3 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 2 ms 2636 KB Output is correct
9 Correct 2 ms 2636 KB Output is correct
10 Correct 2 ms 2636 KB Output is correct
11 Correct 2 ms 2636 KB Output is correct
12 Correct 2 ms 2636 KB Output is correct
13 Correct 3 ms 2636 KB Output is correct
14 Correct 2 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 3 ms 2636 KB Output is correct
18 Correct 2 ms 2636 KB Output is correct
19 Correct 2 ms 2636 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 2 ms 2636 KB Output is correct
23 Correct 2 ms 2636 KB Output is correct
24 Correct 2 ms 2636 KB Output is correct
25 Correct 2 ms 2636 KB Output is correct
26 Correct 3 ms 2732 KB Output is correct
27 Correct 3 ms 2764 KB Output is correct
28 Correct 3 ms 2764 KB Output is correct
29 Correct 2 ms 2636 KB Output is correct
30 Correct 3 ms 2764 KB Output is correct
31 Correct 3 ms 2892 KB Output is correct
32 Incorrect 3 ms 2636 KB Output isn't correct
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 67 ms 11960 KB Output is correct
2 Correct 61 ms 11656 KB Output is correct
3 Correct 41 ms 10196 KB Output is correct
4 Correct 8 ms 3916 KB Output is correct
5 Correct 6 ms 3404 KB Output is correct
6 Correct 14 ms 4668 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 26 ms 6476 KB Output is correct
9 Correct 36 ms 8616 KB Output is correct
10 Correct 3 ms 2684 KB Output is correct
11 Correct 46 ms 9292 KB Output is correct
12 Correct 83 ms 10564 KB Output is correct
13 Correct 2 ms 2636 KB Output is correct
14 Correct 3 ms 2636 KB Output is correct
15 Correct 2 ms 2764 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 3 ms 2636 KB Output is correct
18 Correct 2 ms 2636 KB Output is correct
19 Correct 2 ms 2636 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 2 ms 2636 KB Output is correct
23 Correct 2 ms 2636 KB Output is correct
24 Correct 2 ms 2636 KB Output is correct
25 Correct 2 ms 2636 KB Output is correct
26 Correct 3 ms 2636 KB Output is correct
27 Correct 2 ms 2636 KB Output is correct
28 Correct 2 ms 2636 KB Output is correct
29 Correct 2 ms 2636 KB Output is correct
30 Correct 3 ms 2636 KB Output is correct
31 Correct 2 ms 2636 KB Output is correct
32 Correct 2 ms 2636 KB Output is correct
33 Correct 2 ms 2636 KB Output is correct
34 Correct 2 ms 2636 KB Output is correct
35 Correct 2 ms 2636 KB Output is correct
36 Correct 2 ms 2636 KB Output is correct
37 Correct 2 ms 2636 KB Output is correct
38 Correct 2 ms 2636 KB Output is correct
39 Correct 73 ms 11940 KB Output is correct
40 Correct 66 ms 11664 KB Output is correct
41 Correct 41 ms 10212 KB Output is correct
42 Correct 9 ms 3928 KB Output is correct
43 Correct 2 ms 2636 KB Output is correct
44 Correct 2 ms 2636 KB Output is correct
45 Correct 2 ms 2636 KB Output is correct
46 Correct 2 ms 2636 KB Output is correct
47 Correct 2 ms 2636 KB Output is correct
48 Correct 2 ms 2636 KB Output is correct
49 Correct 2 ms 2636 KB Output is correct
50 Correct 2 ms 2636 KB Output is correct
51 Correct 2 ms 2636 KB Output is correct
52 Correct 2 ms 2636 KB Output is correct
53 Correct 2 ms 2636 KB Output is correct
54 Correct 2 ms 2636 KB Output is correct
55 Correct 2 ms 2636 KB Output is correct
56 Correct 2 ms 2636 KB Output is correct
57 Correct 103 ms 9412 KB Output is correct
58 Correct 74 ms 9412 KB Output is correct
59 Correct 81 ms 9396 KB Output is correct
60 Correct 70 ms 9316 KB Output is correct
61 Correct 74 ms 9384 KB Output is correct
62 Correct 103 ms 9248 KB Output is correct
63 Correct 74 ms 9024 KB Output is correct
64 Correct 77 ms 9140 KB Output is correct
65 Correct 74 ms 9060 KB Output is correct
66 Correct 68 ms 9140 KB Output is correct
67 Correct 80 ms 9372 KB Output is correct
68 Correct 135 ms 9404 KB Output is correct
69 Correct 116 ms 9340 KB Output is correct
70 Correct 105 ms 9380 KB Output is correct
71 Correct 3 ms 2636 KB Output is correct
72 Correct 4 ms 2764 KB Output is correct
73 Correct 4 ms 2764 KB Output is correct
74 Correct 3 ms 2764 KB Output is correct
75 Correct 4 ms 2764 KB Output is correct
76 Correct 4 ms 2764 KB Output is correct
77 Correct 5 ms 2764 KB Output is correct
78 Correct 4 ms 2764 KB Output is correct
79 Correct 4 ms 2764 KB Output is correct
80 Correct 110 ms 9348 KB Output is correct
81 Correct 105 ms 9292 KB Output is correct
82 Correct 93 ms 9304 KB Output is correct
83 Correct 88 ms 9256 KB Output is correct
84 Correct 3 ms 2816 KB Output is correct
85 Correct 3 ms 2764 KB Output is correct
86 Correct 3 ms 2764 KB Output is correct
87 Correct 3 ms 2764 KB Output is correct
88 Correct 3 ms 2764 KB Output is correct
89 Correct 4 ms 2764 KB Output is correct
90 Correct 4 ms 2764 KB Output is correct
91 Correct 5 ms 2764 KB Output is correct
92 Correct 3 ms 2764 KB Output is correct
93 Correct 3 ms 2764 KB Output is correct
94 Correct 2 ms 2636 KB Output is correct
95 Correct 2 ms 2636 KB Output is correct
96 Correct 2 ms 2648 KB Output is correct
97 Correct 2 ms 2636 KB Output is correct
98 Correct 2 ms 2636 KB Output is correct
99 Correct 2 ms 2636 KB Output is correct
100 Correct 2 ms 2636 KB Output is correct
101 Correct 2 ms 2636 KB Output is correct
102 Correct 2 ms 2636 KB Output is correct
103 Correct 2 ms 2636 KB Output is correct
104 Correct 7 ms 3404 KB Output is correct
105 Correct 13 ms 4684 KB Output is correct
106 Correct 2 ms 2636 KB Output is correct
107 Correct 26 ms 6552 KB Output is correct
108 Correct 40 ms 8652 KB Output is correct
109 Correct 2 ms 2636 KB Output is correct
110 Correct 53 ms 9404 KB Output is correct
111 Correct 72 ms 10676 KB Output is correct
112 Correct 2 ms 2636 KB Output is correct
113 Correct 95 ms 16304 KB Output is correct
114 Correct 32 ms 7120 KB Output is correct
115 Incorrect 30 ms 7624 KB Output isn't correct
116 Halted 0 ms 0 KB -