Submission #990820

# Submission time Handle Problem Language Result Execution time Memory
990820 2024-05-31T12:29:59 Z stdfloat Dreaming (IOI13_dreaming) C++17
47 / 100
51 ms 19440 KB
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;

#define ff  first
#define ss  second
#define pii pair<int, int>

int cnt;

vector<int> v, u, vis;

vector<pii> a;

vector<vector<pii>> E;

int dfsv(int x, int p = -1) {
    for (auto [i, w] : E[x])
        if (i != p) v[x] = max(v[x], w + dfsv(i, x));

    return v[x];
}

void dfsu(int x) {
    vis[x] = cnt;

    for (auto [i, w] : E[x])
        if (!vis[i]) a.push_back({w + v[i], i});

    sort(a.rbegin(), a.rend());

    for (auto [i, w] : E[x])
        if (!vis[i]) u[i] = w + max(u[x], (a[0].ss != i ? a[0].ff : (1 < (int)a.size() ? a[1].ff : 0)));

    a.clear();
    for (auto [i, w] : E[x])
        if (!vis[i]) dfsu(i);
}

int travelTime(int n, int m, int L, int A[], int B[], int T[]) {
    E.assign(n, {});
    for (int i = 0; i < m; i++) {
        E[A[i]].push_back({B[i], T[i]});
        E[B[i]].push_back({A[i], T[i]});
    }

    vis.assign(n, 0);
    v.assign(n, 0); u.assign(n, 0);
    for (int i = 0; i < n; i++) {
        if (!vis[i]) {
            cnt++;
            dfsv(i); dfsu(i);
        }
    }

    int mx = 0;
    vector<int> mn(n + 1, INT_MAX);
    for (int i = 0; i < n; i++) {
        mx = max({mx, v[i], u[i]});
        mn[vis[i]] = min(mn[vis[i]], max(v[i], u[i]));
    }

    sort(mn.begin(), mn.end());
    while (mn.back() == INT_MAX) mn.pop_back();
    reverse(mn.begin(), mn.end());

    set<int> s(vis.begin(), vis.end());
    assert((int)s.size() == 2);
    assert((int)mn.size() == 2);

    if (1 < (int)mn.size()) mx = max(mx, mn[0] + L + mn[1]);
    if (2 < (int)mn.size()) mx = max(mx, mn[1] + (L << 1) + mn[2]);

    return mx;
}
# Verdict Execution time Memory Grader output
1 Correct 34 ms 13400 KB Output is correct
2 Correct 33 ms 12880 KB Output is correct
3 Correct 23 ms 10832 KB Output is correct
4 Correct 5 ms 2136 KB Output is correct
5 Correct 4 ms 1372 KB Output is correct
6 Correct 8 ms 3148 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 16 ms 5844 KB Output is correct
9 Correct 21 ms 8784 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 32 ms 9664 KB Output is correct
12 Correct 39 ms 11348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 388 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 420 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 13400 KB Output is correct
2 Correct 33 ms 12880 KB Output is correct
3 Correct 23 ms 10832 KB Output is correct
4 Correct 5 ms 2136 KB Output is correct
5 Correct 4 ms 1372 KB Output is correct
6 Correct 8 ms 3148 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 16 ms 5844 KB Output is correct
9 Correct 21 ms 8784 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 32 ms 9664 KB Output is correct
12 Correct 39 ms 11348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 388 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 420 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 36 ms 13536 KB Output is correct
40 Correct 38 ms 13328 KB Output is correct
41 Correct 27 ms 11100 KB Output is correct
42 Correct 5 ms 2140 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 360 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 39 ms 9728 KB Output is correct
58 Correct 40 ms 9812 KB Output is correct
59 Correct 42 ms 9812 KB Output is correct
60 Correct 39 ms 9756 KB Output is correct
61 Correct 40 ms 9556 KB Output is correct
62 Correct 45 ms 9552 KB Output is correct
63 Correct 36 ms 9296 KB Output is correct
64 Correct 37 ms 9300 KB Output is correct
65 Correct 46 ms 9552 KB Output is correct
66 Correct 36 ms 9812 KB Output is correct
67 Correct 43 ms 9812 KB Output is correct
68 Correct 39 ms 9552 KB Output is correct
69 Correct 43 ms 9808 KB Output is correct
70 Correct 41 ms 9556 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 1 ms 616 KB Output is correct
73 Correct 1 ms 604 KB Output is correct
74 Correct 2 ms 604 KB Output is correct
75 Correct 1 ms 604 KB Output is correct
76 Correct 1 ms 604 KB Output is correct
77 Correct 1 ms 604 KB Output is correct
78 Correct 1 ms 604 KB Output is correct
79 Correct 1 ms 604 KB Output is correct
80 Correct 42 ms 9896 KB Output is correct
81 Correct 42 ms 9820 KB Output is correct
82 Correct 42 ms 9580 KB Output is correct
83 Correct 37 ms 9312 KB Output is correct
84 Correct 1 ms 600 KB Output is correct
85 Correct 1 ms 452 KB Output is correct
86 Correct 1 ms 604 KB Output is correct
87 Correct 1 ms 604 KB Output is correct
88 Correct 1 ms 604 KB Output is correct
89 Correct 1 ms 604 KB Output is correct
90 Correct 1 ms 604 KB Output is correct
91 Correct 1 ms 604 KB Output is correct
92 Correct 1 ms 604 KB Output is correct
93 Correct 1 ms 604 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 344 KB Output is correct
97 Correct 1 ms 344 KB Output is correct
98 Correct 0 ms 348 KB Output is correct
99 Correct 0 ms 348 KB Output is correct
100 Correct 0 ms 348 KB Output is correct
101 Correct 0 ms 348 KB Output is correct
102 Correct 0 ms 348 KB Output is correct
103 Correct 0 ms 348 KB Output is correct
104 Correct 4 ms 1372 KB Output is correct
105 Correct 9 ms 3160 KB Output is correct
106 Correct 0 ms 348 KB Output is correct
107 Correct 17 ms 5696 KB Output is correct
108 Correct 23 ms 8788 KB Output is correct
109 Correct 1 ms 348 KB Output is correct
110 Correct 31 ms 9752 KB Output is correct
111 Correct 35 ms 11604 KB Output is correct
112 Correct 1 ms 348 KB Output is correct
113 Correct 51 ms 19440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 31 ms 18524 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 388 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 420 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Runtime error 1 ms 604 KB Execution killed with signal 6
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 13400 KB Output is correct
2 Correct 33 ms 12880 KB Output is correct
3 Correct 23 ms 10832 KB Output is correct
4 Correct 5 ms 2136 KB Output is correct
5 Correct 4 ms 1372 KB Output is correct
6 Correct 8 ms 3148 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 16 ms 5844 KB Output is correct
9 Correct 21 ms 8784 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 32 ms 9664 KB Output is correct
12 Correct 39 ms 11348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 388 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 420 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 36 ms 13536 KB Output is correct
40 Correct 38 ms 13328 KB Output is correct
41 Correct 27 ms 11100 KB Output is correct
42 Correct 5 ms 2140 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 360 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 39 ms 9728 KB Output is correct
58 Correct 40 ms 9812 KB Output is correct
59 Correct 42 ms 9812 KB Output is correct
60 Correct 39 ms 9756 KB Output is correct
61 Correct 40 ms 9556 KB Output is correct
62 Correct 45 ms 9552 KB Output is correct
63 Correct 36 ms 9296 KB Output is correct
64 Correct 37 ms 9300 KB Output is correct
65 Correct 46 ms 9552 KB Output is correct
66 Correct 36 ms 9812 KB Output is correct
67 Correct 43 ms 9812 KB Output is correct
68 Correct 39 ms 9552 KB Output is correct
69 Correct 43 ms 9808 KB Output is correct
70 Correct 41 ms 9556 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 1 ms 616 KB Output is correct
73 Correct 1 ms 604 KB Output is correct
74 Correct 2 ms 604 KB Output is correct
75 Correct 1 ms 604 KB Output is correct
76 Correct 1 ms 604 KB Output is correct
77 Correct 1 ms 604 KB Output is correct
78 Correct 1 ms 604 KB Output is correct
79 Correct 1 ms 604 KB Output is correct
80 Correct 42 ms 9896 KB Output is correct
81 Correct 42 ms 9820 KB Output is correct
82 Correct 42 ms 9580 KB Output is correct
83 Correct 37 ms 9312 KB Output is correct
84 Correct 1 ms 600 KB Output is correct
85 Correct 1 ms 452 KB Output is correct
86 Correct 1 ms 604 KB Output is correct
87 Correct 1 ms 604 KB Output is correct
88 Correct 1 ms 604 KB Output is correct
89 Correct 1 ms 604 KB Output is correct
90 Correct 1 ms 604 KB Output is correct
91 Correct 1 ms 604 KB Output is correct
92 Correct 1 ms 604 KB Output is correct
93 Correct 1 ms 604 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 344 KB Output is correct
97 Correct 1 ms 344 KB Output is correct
98 Correct 0 ms 348 KB Output is correct
99 Correct 0 ms 348 KB Output is correct
100 Correct 0 ms 348 KB Output is correct
101 Correct 0 ms 348 KB Output is correct
102 Correct 0 ms 348 KB Output is correct
103 Correct 0 ms 348 KB Output is correct
104 Correct 4 ms 1372 KB Output is correct
105 Correct 9 ms 3160 KB Output is correct
106 Correct 0 ms 348 KB Output is correct
107 Correct 17 ms 5696 KB Output is correct
108 Correct 23 ms 8788 KB Output is correct
109 Correct 1 ms 348 KB Output is correct
110 Correct 31 ms 9752 KB Output is correct
111 Correct 35 ms 11604 KB Output is correct
112 Correct 1 ms 348 KB Output is correct
113 Correct 51 ms 19440 KB Output is correct
114 Runtime error 31 ms 18524 KB Execution killed with signal 6
115 Halted 0 ms 0 KB -