Submission #727108

# Submission time Handle Problem Language Result Execution time Memory
727108 2023-04-20T04:08:22 Z hoainiem Dreaming (IOI13_dreaming) C++14
59 / 100
1000 ms 9960 KB
#include "dreaming.h"
#include <bits/stdc++.h>
#define fi first
#define se second
#define nmax 100008
const int inf = 1e9 + 7;
using namespace std;
typedef pair<int, int> pii;
pii operator+(pii x, int y){
    return (x.fi <= y) ? make_pair(y, x.fi) : ((x.se < y) ? make_pair(x.fi, y) : x);
}
pii operator+(pii x, pii y){
    return (x + y.fi) + y.se;
}
vector<pii>vt, l[nmax];
bool kt[nmax], vis[nmax];
int n, d = 0, ans = inf, diameter = 0, dis[2][nmax];
stack<int>s, his;
int a[nmax];
pii pf[nmax], sf[nmax];
void bfs(int root, int id){
    fill(dis[id], dis[id] + nmax, -1);
    s.push(root);
    dis[id][root] = 0;
    while (!s.empty()){
        int u = s.top();
        s.pop();
        his.push(u);
        kt[u] = vis[u] = true;
        for (pii it : l[u])
            if (dis[id][it.fi] == -1){
                dis[id][it.fi] = dis[id][u] + it.se;
                s.push(it.fi);
            }
    }
}
int calc(int rt){
    while (!his.empty()){
        kt[his.top()] = false;
        his.pop();
    }
    bfs(rt, 0);
    int u = 0, v = 0, res = inf;
    for (int i = 1; i < n; i++)
        if (dis[0][u] < dis[0][i])
            u = i;
    bfs(u, 1);
    for (int i = 1; i < n; i++)
        if (dis[1][v] < dis[1][i])
            v = i;
    bfs(v, 0);
    for (int i = 0; i < n; i++)
        if (kt[i])
            res = min(res, max(dis[0][i], dis[1][i]));
    diameter = max(diameter, dis[0][u]);
    return res;
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    n = N;
    for (int i = 0; i < M; i++){
        int u = A[i], v = B[i], w = T[i];
        l[u].push_back({v, w});
        l[v].push_back({u, w});
    }
//    assert(M == N - 2);
    fill(vis, vis + n + 1, false);
    pf[0] = {-inf, -inf};
    for (int i = 0; i < N; i++)
        if (!vis[i]){
            a[++d] = calc(i);
            pf[d] = pf[d - 1] + a[d];
        }
    if (M == N - 2)
        return max(diameter, a[2] + a[1] + L);
    sf[d + 1] = {-inf, -inf};
    for (int i = d; i > 0; i--)
        sf[i] = sf[i + 1] + a[i];
    for (int i = 1; i <= d; i++){
        pii cur = pf[i - 1] + sf[i + 1];
        ans = min(ans, max({diameter, cur.fi + cur.se + L * 2, cur.fi + a[i] + L}));
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 59 ms 8692 KB Output is correct
2 Correct 39 ms 8668 KB Output is correct
3 Correct 26 ms 6868 KB Output is correct
4 Correct 7 ms 4248 KB Output is correct
5 Correct 6 ms 3948 KB Output is correct
6 Correct 11 ms 4588 KB Output is correct
7 Correct 3 ms 3412 KB Output is correct
8 Correct 24 ms 5464 KB Output is correct
9 Correct 34 ms 6096 KB Output is correct
10 Correct 2 ms 3412 KB Output is correct
11 Correct 38 ms 7092 KB Output is correct
12 Correct 45 ms 7900 KB Output is correct
13 Correct 3 ms 3412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3460 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Correct 3 ms 3540 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 2 ms 3412 KB Output is correct
6 Correct 2 ms 3412 KB Output is correct
7 Correct 2 ms 3412 KB Output is correct
8 Correct 2 ms 3412 KB Output is correct
9 Correct 2 ms 3412 KB Output is correct
10 Correct 2 ms 3412 KB Output is correct
11 Correct 2 ms 3412 KB Output is correct
12 Correct 2 ms 3412 KB Output is correct
13 Correct 2 ms 3412 KB Output is correct
14 Correct 2 ms 3412 KB Output is correct
15 Correct 2 ms 3412 KB Output is correct
16 Correct 2 ms 3412 KB Output is correct
17 Correct 2 ms 3412 KB Output is correct
18 Correct 2 ms 3412 KB Output is correct
19 Correct 2 ms 3412 KB Output is correct
20 Correct 3 ms 3412 KB Output is correct
21 Correct 3 ms 3412 KB Output is correct
22 Correct 2 ms 3412 KB Output is correct
23 Correct 2 ms 3412 KB Output is correct
24 Correct 2 ms 3412 KB Output is correct
25 Correct 2 ms 3412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 8692 KB Output is correct
2 Correct 39 ms 8668 KB Output is correct
3 Correct 26 ms 6868 KB Output is correct
4 Correct 7 ms 4248 KB Output is correct
5 Correct 6 ms 3948 KB Output is correct
6 Correct 11 ms 4588 KB Output is correct
7 Correct 3 ms 3412 KB Output is correct
8 Correct 24 ms 5464 KB Output is correct
9 Correct 34 ms 6096 KB Output is correct
10 Correct 2 ms 3412 KB Output is correct
11 Correct 38 ms 7092 KB Output is correct
12 Correct 45 ms 7900 KB Output is correct
13 Correct 3 ms 3412 KB Output is correct
14 Correct 2 ms 3460 KB Output is correct
15 Correct 2 ms 3412 KB Output is correct
16 Correct 3 ms 3540 KB Output is correct
17 Correct 2 ms 3412 KB Output is correct
18 Correct 2 ms 3412 KB Output is correct
19 Correct 2 ms 3412 KB Output is correct
20 Correct 2 ms 3412 KB Output is correct
21 Correct 2 ms 3412 KB Output is correct
22 Correct 2 ms 3412 KB Output is correct
23 Correct 2 ms 3412 KB Output is correct
24 Correct 2 ms 3412 KB Output is correct
25 Correct 2 ms 3412 KB Output is correct
26 Correct 2 ms 3412 KB Output is correct
27 Correct 2 ms 3412 KB Output is correct
28 Correct 2 ms 3412 KB Output is correct
29 Correct 2 ms 3412 KB Output is correct
30 Correct 2 ms 3412 KB Output is correct
31 Correct 2 ms 3412 KB Output is correct
32 Correct 2 ms 3412 KB Output is correct
33 Correct 3 ms 3412 KB Output is correct
34 Correct 3 ms 3412 KB Output is correct
35 Correct 2 ms 3412 KB Output is correct
36 Correct 2 ms 3412 KB Output is correct
37 Correct 2 ms 3412 KB Output is correct
38 Correct 2 ms 3412 KB Output is correct
39 Correct 39 ms 8576 KB Output is correct
40 Correct 39 ms 8624 KB Output is correct
41 Correct 29 ms 6836 KB Output is correct
42 Correct 7 ms 4160 KB Output is correct
43 Correct 3 ms 3412 KB Output is correct
44 Correct 3 ms 3412 KB Output is correct
45 Correct 3 ms 3412 KB Output is correct
46 Correct 2 ms 3412 KB Output is correct
47 Correct 3 ms 3412 KB Output is correct
48 Correct 2 ms 3412 KB Output is correct
49 Correct 2 ms 3412 KB Output is correct
50 Correct 2 ms 3412 KB Output is correct
51 Correct 2 ms 3412 KB Output is correct
52 Correct 2 ms 3412 KB Output is correct
53 Correct 2 ms 3412 KB Output is correct
54 Correct 2 ms 3412 KB Output is correct
55 Correct 2 ms 3412 KB Output is correct
56 Correct 2 ms 3412 KB Output is correct
57 Correct 81 ms 9960 KB Output is correct
58 Correct 75 ms 9416 KB Output is correct
59 Correct 61 ms 9700 KB Output is correct
60 Correct 71 ms 9380 KB Output is correct
61 Correct 61 ms 9708 KB Output is correct
62 Correct 81 ms 9348 KB Output is correct
63 Correct 61 ms 9720 KB Output is correct
64 Correct 64 ms 9716 KB Output is correct
65 Correct 74 ms 9712 KB Output is correct
66 Correct 72 ms 9704 KB Output is correct
67 Correct 89 ms 9736 KB Output is correct
68 Correct 65 ms 9724 KB Output is correct
69 Correct 87 ms 9268 KB Output is correct
70 Correct 96 ms 9316 KB Output is correct
71 Correct 2 ms 3412 KB Output is correct
72 Correct 4 ms 3540 KB Output is correct
73 Correct 4 ms 3640 KB Output is correct
74 Correct 4 ms 3540 KB Output is correct
75 Correct 4 ms 3636 KB Output is correct
76 Correct 3 ms 3540 KB Output is correct
77 Correct 3 ms 3608 KB Output is correct
78 Correct 3 ms 3540 KB Output is correct
79 Correct 3 ms 3540 KB Output is correct
80 Correct 86 ms 9472 KB Output is correct
81 Correct 73 ms 9388 KB Output is correct
82 Correct 63 ms 9592 KB Output is correct
83 Correct 67 ms 9848 KB Output is correct
84 Correct 3 ms 3540 KB Output is correct
85 Correct 2 ms 3540 KB Output is correct
86 Correct 3 ms 3540 KB Output is correct
87 Correct 3 ms 3540 KB Output is correct
88 Correct 3 ms 3540 KB Output is correct
89 Correct 4 ms 3540 KB Output is correct
90 Correct 3 ms 3540 KB Output is correct
91 Correct 4 ms 3540 KB Output is correct
92 Correct 3 ms 3540 KB Output is correct
93 Correct 4 ms 3540 KB Output is correct
94 Correct 2 ms 3412 KB Output is correct
95 Correct 2 ms 3412 KB Output is correct
96 Correct 3 ms 3412 KB Output is correct
97 Correct 2 ms 3412 KB Output is correct
98 Correct 3 ms 3412 KB Output is correct
99 Correct 2 ms 3460 KB Output is correct
100 Correct 2 ms 3412 KB Output is correct
101 Correct 2 ms 3412 KB Output is correct
102 Correct 2 ms 3412 KB Output is correct
103 Correct 2 ms 3412 KB Output is correct
104 Correct 6 ms 3924 KB Output is correct
105 Correct 11 ms 4616 KB Output is correct
106 Correct 2 ms 3496 KB Output is correct
107 Correct 23 ms 5460 KB Output is correct
108 Correct 29 ms 6200 KB Output is correct
109 Correct 2 ms 3412 KB Output is correct
110 Correct 47 ms 7068 KB Output is correct
111 Correct 44 ms 7848 KB Output is correct
112 Correct 2 ms 3412 KB Output is correct
113 Correct 86 ms 9052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 6092 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3460 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Correct 3 ms 3540 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 2 ms 3412 KB Output is correct
6 Correct 2 ms 3412 KB Output is correct
7 Correct 2 ms 3412 KB Output is correct
8 Correct 2 ms 3412 KB Output is correct
9 Correct 2 ms 3412 KB Output is correct
10 Correct 2 ms 3412 KB Output is correct
11 Correct 2 ms 3412 KB Output is correct
12 Correct 2 ms 3412 KB Output is correct
13 Correct 2 ms 3412 KB Output is correct
14 Correct 2 ms 3412 KB Output is correct
15 Correct 2 ms 3412 KB Output is correct
16 Correct 2 ms 3412 KB Output is correct
17 Correct 2 ms 3412 KB Output is correct
18 Correct 2 ms 3412 KB Output is correct
19 Correct 2 ms 3412 KB Output is correct
20 Correct 3 ms 3412 KB Output is correct
21 Correct 3 ms 3412 KB Output is correct
22 Correct 2 ms 3412 KB Output is correct
23 Correct 2 ms 3412 KB Output is correct
24 Correct 2 ms 3412 KB Output is correct
25 Correct 2 ms 3412 KB Output is correct
26 Correct 8 ms 3412 KB Output is correct
27 Correct 20 ms 3528 KB Output is correct
28 Correct 23 ms 3620 KB Output is correct
29 Correct 7 ms 3412 KB Output is correct
30 Correct 13 ms 3580 KB Output is correct
31 Correct 21 ms 3540 KB Output is correct
32 Correct 6 ms 3412 KB Output is correct
33 Correct 13 ms 3584 KB Output is correct
34 Correct 21 ms 3636 KB Output is correct
35 Correct 2 ms 3412 KB Output is correct
36 Correct 2 ms 3412 KB Output is correct
37 Correct 3 ms 3420 KB Output is correct
38 Correct 2 ms 3412 KB Output is correct
39 Correct 2 ms 3412 KB Output is correct
40 Correct 4 ms 3412 KB Output is correct
41 Correct 4 ms 3412 KB Output is correct
42 Correct 2 ms 3412 KB Output is correct
43 Correct 2 ms 3412 KB Output is correct
44 Correct 2 ms 3412 KB Output is correct
45 Correct 2 ms 3412 KB Output is correct
46 Correct 2 ms 3412 KB Output is correct
47 Correct 2 ms 3412 KB Output is correct
48 Correct 2 ms 3412 KB Output is correct
49 Correct 2 ms 3412 KB Output is correct
50 Correct 2 ms 3412 KB Output is correct
51 Correct 2 ms 3412 KB Output is correct
52 Correct 2 ms 3412 KB Output is correct
53 Correct 2 ms 3412 KB Output is correct
54 Correct 3 ms 3540 KB Output is correct
55 Correct 3 ms 3652 KB Output is correct
56 Correct 62 ms 3568 KB Output is correct
57 Correct 105 ms 3520 KB Output is correct
58 Correct 3 ms 3540 KB Output is correct
59 Correct 3 ms 3540 KB Output is correct
60 Correct 84 ms 3560 KB Output is correct
61 Correct 97 ms 3776 KB Output is correct
62 Correct 4 ms 3540 KB Output is correct
63 Correct 4 ms 3660 KB Output is correct
64 Correct 134 ms 3500 KB Output is correct
65 Correct 51 ms 3540 KB Output is correct
66 Correct 3 ms 3540 KB Output is correct
67 Correct 3 ms 3540 KB Output is correct
68 Correct 47 ms 3540 KB Output is correct
69 Correct 46 ms 3596 KB Output is correct
70 Correct 92 ms 3540 KB Output is correct
71 Correct 83 ms 3540 KB Output is correct
72 Correct 3 ms 3544 KB Output is correct
73 Correct 3 ms 3540 KB Output is correct
74 Correct 12 ms 3540 KB Output is correct
75 Correct 10 ms 3540 KB Output is correct
76 Correct 3 ms 3540 KB Output is correct
77 Correct 3 ms 3540 KB Output is correct
78 Correct 89 ms 3540 KB Output is correct
79 Correct 106 ms 3664 KB Output is correct
80 Correct 115 ms 3496 KB Output is correct
81 Correct 122 ms 3492 KB Output is correct
82 Correct 17 ms 3616 KB Output is correct
83 Correct 17 ms 3676 KB Output is correct
84 Correct 88 ms 3560 KB Output is correct
85 Correct 162 ms 3532 KB Output is correct
86 Correct 51 ms 3596 KB Output is correct
87 Correct 17 ms 3652 KB Output is correct
88 Correct 61 ms 3540 KB Output is correct
89 Correct 73 ms 3584 KB Output is correct
90 Correct 97 ms 3556 KB Output is correct
91 Correct 90 ms 3532 KB Output is correct
92 Correct 5 ms 3540 KB Output is correct
93 Correct 3 ms 3540 KB Output is correct
94 Correct 3 ms 3540 KB Output is correct
95 Correct 3 ms 3540 KB Output is correct
96 Correct 3 ms 3540 KB Output is correct
97 Correct 3 ms 3540 KB Output is correct
98 Correct 3 ms 3540 KB Output is correct
99 Correct 3 ms 3540 KB Output is correct
100 Correct 3 ms 3540 KB Output is correct
101 Correct 3 ms 3540 KB Output is correct
102 Correct 2 ms 3412 KB Output is correct
103 Correct 2 ms 3412 KB Output is correct
104 Correct 2 ms 3412 KB Output is correct
105 Correct 3 ms 3412 KB Output is correct
106 Correct 3 ms 3412 KB Output is correct
107 Correct 2 ms 3412 KB Output is correct
108 Correct 2 ms 3412 KB Output is correct
109 Correct 2 ms 3412 KB Output is correct
110 Correct 2 ms 3412 KB Output is correct
111 Correct 2 ms 3412 KB Output is correct
112 Correct 2 ms 3412 KB Output is correct
113 Correct 2 ms 3412 KB Output is correct
114 Correct 2 ms 3412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 8692 KB Output is correct
2 Correct 39 ms 8668 KB Output is correct
3 Correct 26 ms 6868 KB Output is correct
4 Correct 7 ms 4248 KB Output is correct
5 Correct 6 ms 3948 KB Output is correct
6 Correct 11 ms 4588 KB Output is correct
7 Correct 3 ms 3412 KB Output is correct
8 Correct 24 ms 5464 KB Output is correct
9 Correct 34 ms 6096 KB Output is correct
10 Correct 2 ms 3412 KB Output is correct
11 Correct 38 ms 7092 KB Output is correct
12 Correct 45 ms 7900 KB Output is correct
13 Correct 3 ms 3412 KB Output is correct
14 Correct 2 ms 3460 KB Output is correct
15 Correct 2 ms 3412 KB Output is correct
16 Correct 3 ms 3540 KB Output is correct
17 Correct 2 ms 3412 KB Output is correct
18 Correct 2 ms 3412 KB Output is correct
19 Correct 2 ms 3412 KB Output is correct
20 Correct 2 ms 3412 KB Output is correct
21 Correct 2 ms 3412 KB Output is correct
22 Correct 2 ms 3412 KB Output is correct
23 Correct 2 ms 3412 KB Output is correct
24 Correct 2 ms 3412 KB Output is correct
25 Correct 2 ms 3412 KB Output is correct
26 Correct 2 ms 3412 KB Output is correct
27 Correct 2 ms 3412 KB Output is correct
28 Correct 2 ms 3412 KB Output is correct
29 Correct 2 ms 3412 KB Output is correct
30 Correct 2 ms 3412 KB Output is correct
31 Correct 2 ms 3412 KB Output is correct
32 Correct 2 ms 3412 KB Output is correct
33 Correct 3 ms 3412 KB Output is correct
34 Correct 3 ms 3412 KB Output is correct
35 Correct 2 ms 3412 KB Output is correct
36 Correct 2 ms 3412 KB Output is correct
37 Correct 2 ms 3412 KB Output is correct
38 Correct 2 ms 3412 KB Output is correct
39 Correct 39 ms 8576 KB Output is correct
40 Correct 39 ms 8624 KB Output is correct
41 Correct 29 ms 6836 KB Output is correct
42 Correct 7 ms 4160 KB Output is correct
43 Correct 3 ms 3412 KB Output is correct
44 Correct 3 ms 3412 KB Output is correct
45 Correct 3 ms 3412 KB Output is correct
46 Correct 2 ms 3412 KB Output is correct
47 Correct 3 ms 3412 KB Output is correct
48 Correct 2 ms 3412 KB Output is correct
49 Correct 2 ms 3412 KB Output is correct
50 Correct 2 ms 3412 KB Output is correct
51 Correct 2 ms 3412 KB Output is correct
52 Correct 2 ms 3412 KB Output is correct
53 Correct 2 ms 3412 KB Output is correct
54 Correct 2 ms 3412 KB Output is correct
55 Correct 2 ms 3412 KB Output is correct
56 Correct 2 ms 3412 KB Output is correct
57 Correct 81 ms 9960 KB Output is correct
58 Correct 75 ms 9416 KB Output is correct
59 Correct 61 ms 9700 KB Output is correct
60 Correct 71 ms 9380 KB Output is correct
61 Correct 61 ms 9708 KB Output is correct
62 Correct 81 ms 9348 KB Output is correct
63 Correct 61 ms 9720 KB Output is correct
64 Correct 64 ms 9716 KB Output is correct
65 Correct 74 ms 9712 KB Output is correct
66 Correct 72 ms 9704 KB Output is correct
67 Correct 89 ms 9736 KB Output is correct
68 Correct 65 ms 9724 KB Output is correct
69 Correct 87 ms 9268 KB Output is correct
70 Correct 96 ms 9316 KB Output is correct
71 Correct 2 ms 3412 KB Output is correct
72 Correct 4 ms 3540 KB Output is correct
73 Correct 4 ms 3640 KB Output is correct
74 Correct 4 ms 3540 KB Output is correct
75 Correct 4 ms 3636 KB Output is correct
76 Correct 3 ms 3540 KB Output is correct
77 Correct 3 ms 3608 KB Output is correct
78 Correct 3 ms 3540 KB Output is correct
79 Correct 3 ms 3540 KB Output is correct
80 Correct 86 ms 9472 KB Output is correct
81 Correct 73 ms 9388 KB Output is correct
82 Correct 63 ms 9592 KB Output is correct
83 Correct 67 ms 9848 KB Output is correct
84 Correct 3 ms 3540 KB Output is correct
85 Correct 2 ms 3540 KB Output is correct
86 Correct 3 ms 3540 KB Output is correct
87 Correct 3 ms 3540 KB Output is correct
88 Correct 3 ms 3540 KB Output is correct
89 Correct 4 ms 3540 KB Output is correct
90 Correct 3 ms 3540 KB Output is correct
91 Correct 4 ms 3540 KB Output is correct
92 Correct 3 ms 3540 KB Output is correct
93 Correct 4 ms 3540 KB Output is correct
94 Correct 2 ms 3412 KB Output is correct
95 Correct 2 ms 3412 KB Output is correct
96 Correct 3 ms 3412 KB Output is correct
97 Correct 2 ms 3412 KB Output is correct
98 Correct 3 ms 3412 KB Output is correct
99 Correct 2 ms 3460 KB Output is correct
100 Correct 2 ms 3412 KB Output is correct
101 Correct 2 ms 3412 KB Output is correct
102 Correct 2 ms 3412 KB Output is correct
103 Correct 2 ms 3412 KB Output is correct
104 Correct 6 ms 3924 KB Output is correct
105 Correct 11 ms 4616 KB Output is correct
106 Correct 2 ms 3496 KB Output is correct
107 Correct 23 ms 5460 KB Output is correct
108 Correct 29 ms 6200 KB Output is correct
109 Correct 2 ms 3412 KB Output is correct
110 Correct 47 ms 7068 KB Output is correct
111 Correct 44 ms 7848 KB Output is correct
112 Correct 2 ms 3412 KB Output is correct
113 Correct 86 ms 9052 KB Output is correct
114 Execution timed out 1071 ms 6092 KB Time limit exceeded
115 Halted 0 ms 0 KB -