Submission #727112

# Submission time Handle Problem Language Result Execution time Memory
727112 2023-04-20T04:14:25 Z hoainiem Dreaming (IOI13_dreaming) C++14
59 / 100
1000 ms 9340 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;
int a[nmax];
pii pf[nmax], sf[nmax];
vector<int>his;
void bfs(int root, int id, int k){
    for (int tmp : his)
        dis[id][tmp] = -1;
    s.push(root);
    dis[id][root] = 0;
    while (!s.empty()){
        int u = s.top();
        s.pop();
        if (k)
            his.push_back(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){
    for (int tmp : his){
        kt[tmp] = false;
        dis[0][tmp] = dis[1][tmp] = -1;
    }
    his.clear();
    bfs(rt, 0, 1);
    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, 0);
    for (int i = 1; i < n; i++)
        if (dis[1][v] < dis[1][i])
            v = i;
    bfs(v, 0, 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[]) {
    memset(dis, -1, sizeof(dis));
    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);
    memset(kt, false, sizeof(kt));
    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 38 ms 8176 KB Output is correct
2 Correct 42 ms 8140 KB Output is correct
3 Correct 29 ms 6524 KB Output is correct
4 Correct 7 ms 4180 KB Output is correct
5 Correct 6 ms 4052 KB Output is correct
6 Correct 11 ms 4652 KB Output is correct
7 Correct 2 ms 3540 KB Output is correct
8 Correct 20 ms 5460 KB Output is correct
9 Correct 27 ms 6100 KB Output is correct
10 Correct 2 ms 3540 KB Output is correct
11 Correct 39 ms 7004 KB Output is correct
12 Correct 43 ms 7652 KB Output is correct
13 Correct 2 ms 3540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3540 KB Output is correct
2 Correct 2 ms 3540 KB Output is correct
3 Correct 2 ms 3540 KB Output is correct
4 Correct 2 ms 3540 KB Output is correct
5 Correct 2 ms 3540 KB Output is correct
6 Correct 2 ms 3540 KB Output is correct
7 Correct 2 ms 3540 KB Output is correct
8 Correct 2 ms 3540 KB Output is correct
9 Correct 2 ms 3540 KB Output is correct
10 Correct 2 ms 3540 KB Output is correct
11 Correct 2 ms 3540 KB Output is correct
12 Correct 2 ms 3540 KB Output is correct
13 Correct 2 ms 3540 KB Output is correct
14 Correct 2 ms 3540 KB Output is correct
15 Correct 2 ms 3540 KB Output is correct
16 Correct 2 ms 3540 KB Output is correct
17 Correct 2 ms 3540 KB Output is correct
18 Correct 2 ms 3540 KB Output is correct
19 Correct 2 ms 3540 KB Output is correct
20 Correct 2 ms 3540 KB Output is correct
21 Correct 2 ms 3540 KB Output is correct
22 Correct 2 ms 3540 KB Output is correct
23 Correct 2 ms 3540 KB Output is correct
24 Correct 2 ms 3540 KB Output is correct
25 Correct 2 ms 3540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 8176 KB Output is correct
2 Correct 42 ms 8140 KB Output is correct
3 Correct 29 ms 6524 KB Output is correct
4 Correct 7 ms 4180 KB Output is correct
5 Correct 6 ms 4052 KB Output is correct
6 Correct 11 ms 4652 KB Output is correct
7 Correct 2 ms 3540 KB Output is correct
8 Correct 20 ms 5460 KB Output is correct
9 Correct 27 ms 6100 KB Output is correct
10 Correct 2 ms 3540 KB Output is correct
11 Correct 39 ms 7004 KB Output is correct
12 Correct 43 ms 7652 KB Output is correct
13 Correct 2 ms 3540 KB Output is correct
14 Correct 2 ms 3540 KB Output is correct
15 Correct 2 ms 3540 KB Output is correct
16 Correct 2 ms 3540 KB Output is correct
17 Correct 2 ms 3540 KB Output is correct
18 Correct 2 ms 3540 KB Output is correct
19 Correct 2 ms 3540 KB Output is correct
20 Correct 2 ms 3540 KB Output is correct
21 Correct 2 ms 3540 KB Output is correct
22 Correct 2 ms 3540 KB Output is correct
23 Correct 2 ms 3540 KB Output is correct
24 Correct 2 ms 3540 KB Output is correct
25 Correct 2 ms 3540 KB Output is correct
26 Correct 2 ms 3540 KB Output is correct
27 Correct 2 ms 3540 KB Output is correct
28 Correct 2 ms 3540 KB Output is correct
29 Correct 2 ms 3540 KB Output is correct
30 Correct 2 ms 3540 KB Output is correct
31 Correct 2 ms 3540 KB Output is correct
32 Correct 2 ms 3540 KB Output is correct
33 Correct 2 ms 3540 KB Output is correct
34 Correct 2 ms 3540 KB Output is correct
35 Correct 2 ms 3540 KB Output is correct
36 Correct 2 ms 3540 KB Output is correct
37 Correct 2 ms 3540 KB Output is correct
38 Correct 2 ms 3540 KB Output is correct
39 Correct 42 ms 8112 KB Output is correct
40 Correct 41 ms 8104 KB Output is correct
41 Correct 28 ms 6492 KB Output is correct
42 Correct 8 ms 4180 KB Output is correct
43 Correct 2 ms 3540 KB Output is correct
44 Correct 3 ms 3540 KB Output is correct
45 Correct 2 ms 3540 KB Output is correct
46 Correct 2 ms 3540 KB Output is correct
47 Correct 2 ms 3540 KB Output is correct
48 Correct 2 ms 3540 KB Output is correct
49 Correct 2 ms 3540 KB Output is correct
50 Correct 3 ms 3540 KB Output is correct
51 Correct 2 ms 3540 KB Output is correct
52 Correct 2 ms 3540 KB Output is correct
53 Correct 2 ms 3540 KB Output is correct
54 Correct 2 ms 3540 KB Output is correct
55 Correct 2 ms 3540 KB Output is correct
56 Correct 2 ms 3540 KB Output is correct
57 Correct 75 ms 9340 KB Output is correct
58 Correct 65 ms 9180 KB Output is correct
59 Correct 74 ms 9204 KB Output is correct
60 Correct 61 ms 8932 KB Output is correct
61 Correct 65 ms 9168 KB Output is correct
62 Correct 63 ms 8984 KB Output is correct
63 Correct 65 ms 9216 KB Output is correct
64 Correct 61 ms 9100 KB Output is correct
65 Correct 58 ms 9040 KB Output is correct
66 Correct 65 ms 9100 KB Output is correct
67 Correct 70 ms 9220 KB Output is correct
68 Correct 66 ms 9288 KB Output is correct
69 Correct 69 ms 8908 KB Output is correct
70 Correct 70 ms 8956 KB Output is correct
71 Correct 2 ms 3540 KB Output is correct
72 Correct 3 ms 3668 KB Output is correct
73 Correct 5 ms 3732 KB Output is correct
74 Correct 3 ms 3668 KB Output is correct
75 Correct 4 ms 3668 KB Output is correct
76 Correct 3 ms 3668 KB Output is correct
77 Correct 3 ms 3668 KB Output is correct
78 Correct 3 ms 3668 KB Output is correct
79 Correct 3 ms 3668 KB Output is correct
80 Correct 65 ms 9240 KB Output is correct
81 Correct 74 ms 9288 KB Output is correct
82 Correct 62 ms 9164 KB Output is correct
83 Correct 63 ms 9184 KB Output is correct
84 Correct 3 ms 3668 KB Output is correct
85 Correct 3 ms 3668 KB Output is correct
86 Correct 3 ms 3668 KB Output is correct
87 Correct 3 ms 3668 KB Output is correct
88 Correct 3 ms 3668 KB Output is correct
89 Correct 3 ms 3668 KB Output is correct
90 Correct 3 ms 3668 KB Output is correct
91 Correct 3 ms 3668 KB Output is correct
92 Correct 3 ms 3668 KB Output is correct
93 Correct 3 ms 3668 KB Output is correct
94 Correct 2 ms 3540 KB Output is correct
95 Correct 2 ms 3540 KB Output is correct
96 Correct 2 ms 3540 KB Output is correct
97 Correct 2 ms 3540 KB Output is correct
98 Correct 2 ms 3540 KB Output is correct
99 Correct 2 ms 3540 KB Output is correct
100 Correct 2 ms 3464 KB Output is correct
101 Correct 2 ms 3540 KB Output is correct
102 Correct 2 ms 3540 KB Output is correct
103 Correct 2 ms 3540 KB Output is correct
104 Correct 7 ms 4052 KB Output is correct
105 Correct 13 ms 4572 KB Output is correct
106 Correct 2 ms 3540 KB Output is correct
107 Correct 25 ms 5460 KB Output is correct
108 Correct 30 ms 6108 KB Output is correct
109 Correct 2 ms 3500 KB Output is correct
110 Correct 44 ms 6964 KB Output is correct
111 Correct 48 ms 7700 KB Output is correct
112 Correct 3 ms 3540 KB Output is correct
113 Correct 63 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 6228 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3540 KB Output is correct
2 Correct 2 ms 3540 KB Output is correct
3 Correct 2 ms 3540 KB Output is correct
4 Correct 2 ms 3540 KB Output is correct
5 Correct 2 ms 3540 KB Output is correct
6 Correct 2 ms 3540 KB Output is correct
7 Correct 2 ms 3540 KB Output is correct
8 Correct 2 ms 3540 KB Output is correct
9 Correct 2 ms 3540 KB Output is correct
10 Correct 2 ms 3540 KB Output is correct
11 Correct 2 ms 3540 KB Output is correct
12 Correct 2 ms 3540 KB Output is correct
13 Correct 2 ms 3540 KB Output is correct
14 Correct 2 ms 3540 KB Output is correct
15 Correct 2 ms 3540 KB Output is correct
16 Correct 2 ms 3540 KB Output is correct
17 Correct 2 ms 3540 KB Output is correct
18 Correct 2 ms 3540 KB Output is correct
19 Correct 2 ms 3540 KB Output is correct
20 Correct 2 ms 3540 KB Output is correct
21 Correct 2 ms 3540 KB Output is correct
22 Correct 2 ms 3540 KB Output is correct
23 Correct 2 ms 3540 KB Output is correct
24 Correct 2 ms 3540 KB Output is correct
25 Correct 2 ms 3540 KB Output is correct
26 Correct 3 ms 3540 KB Output is correct
27 Correct 6 ms 3656 KB Output is correct
28 Correct 10 ms 3668 KB Output is correct
29 Correct 3 ms 3540 KB Output is correct
30 Correct 5 ms 3588 KB Output is correct
31 Correct 8 ms 3668 KB Output is correct
32 Correct 3 ms 3540 KB Output is correct
33 Correct 4 ms 3668 KB Output is correct
34 Correct 7 ms 3668 KB Output is correct
35 Correct 2 ms 3540 KB Output is correct
36 Correct 2 ms 3540 KB Output is correct
37 Correct 2 ms 3540 KB Output is correct
38 Correct 2 ms 3540 KB Output is correct
39 Correct 2 ms 3540 KB Output is correct
40 Correct 2 ms 3540 KB Output is correct
41 Correct 2 ms 3540 KB Output is correct
42 Correct 2 ms 3540 KB Output is correct
43 Correct 2 ms 3540 KB Output is correct
44 Correct 2 ms 3540 KB Output is correct
45 Correct 2 ms 3540 KB Output is correct
46 Correct 2 ms 3540 KB Output is correct
47 Correct 2 ms 3540 KB Output is correct
48 Correct 2 ms 3540 KB Output is correct
49 Correct 2 ms 3540 KB Output is correct
50 Correct 2 ms 3540 KB Output is correct
51 Correct 2 ms 3540 KB Output is correct
52 Correct 2 ms 3540 KB Output is correct
53 Correct 2 ms 3540 KB Output is correct
54 Correct 4 ms 3668 KB Output is correct
55 Correct 3 ms 3668 KB Output is correct
56 Correct 20 ms 3668 KB Output is correct
57 Correct 33 ms 3540 KB Output is correct
58 Correct 3 ms 3668 KB Output is correct
59 Correct 3 ms 3668 KB Output is correct
60 Correct 26 ms 3664 KB Output is correct
61 Correct 31 ms 3620 KB Output is correct
62 Correct 3 ms 3668 KB Output is correct
63 Correct 3 ms 3668 KB Output is correct
64 Correct 37 ms 3540 KB Output is correct
65 Correct 18 ms 3688 KB Output is correct
66 Correct 3 ms 3668 KB Output is correct
67 Correct 3 ms 3668 KB Output is correct
68 Correct 16 ms 3668 KB Output is correct
69 Correct 15 ms 3668 KB Output is correct
70 Correct 30 ms 3648 KB Output is correct
71 Correct 28 ms 3640 KB Output is correct
72 Correct 3 ms 3668 KB Output is correct
73 Correct 3 ms 3668 KB Output is correct
74 Correct 5 ms 3668 KB Output is correct
75 Correct 5 ms 3668 KB Output is correct
76 Correct 4 ms 3668 KB Output is correct
77 Correct 3 ms 3680 KB Output is correct
78 Correct 30 ms 3640 KB Output is correct
79 Correct 28 ms 3644 KB Output is correct
80 Correct 39 ms 3588 KB Output is correct
81 Correct 40 ms 3580 KB Output is correct
82 Correct 8 ms 3668 KB Output is correct
83 Correct 7 ms 3668 KB Output is correct
84 Correct 30 ms 3644 KB Output is correct
85 Correct 42 ms 3712 KB Output is correct
86 Correct 17 ms 3692 KB Output is correct
87 Correct 7 ms 3668 KB Output is correct
88 Correct 19 ms 3668 KB Output is correct
89 Correct 19 ms 3676 KB Output is correct
90 Correct 28 ms 3772 KB Output is correct
91 Correct 28 ms 3648 KB Output is correct
92 Correct 3 ms 3668 KB Output is correct
93 Correct 3 ms 3668 KB Output is correct
94 Correct 3 ms 3668 KB Output is correct
95 Correct 3 ms 3668 KB Output is correct
96 Correct 3 ms 3668 KB Output is correct
97 Correct 3 ms 3668 KB Output is correct
98 Correct 3 ms 3668 KB Output is correct
99 Correct 3 ms 3668 KB Output is correct
100 Correct 3 ms 3668 KB Output is correct
101 Correct 3 ms 3668 KB Output is correct
102 Correct 2 ms 3560 KB Output is correct
103 Correct 2 ms 3540 KB Output is correct
104 Correct 2 ms 3540 KB Output is correct
105 Correct 2 ms 3540 KB Output is correct
106 Correct 2 ms 3540 KB Output is correct
107 Correct 2 ms 3540 KB Output is correct
108 Correct 2 ms 3540 KB Output is correct
109 Correct 3 ms 3540 KB Output is correct
110 Correct 2 ms 3540 KB Output is correct
111 Correct 2 ms 3540 KB Output is correct
112 Correct 2 ms 3540 KB Output is correct
113 Correct 2 ms 3540 KB Output is correct
114 Correct 2 ms 3540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 8176 KB Output is correct
2 Correct 42 ms 8140 KB Output is correct
3 Correct 29 ms 6524 KB Output is correct
4 Correct 7 ms 4180 KB Output is correct
5 Correct 6 ms 4052 KB Output is correct
6 Correct 11 ms 4652 KB Output is correct
7 Correct 2 ms 3540 KB Output is correct
8 Correct 20 ms 5460 KB Output is correct
9 Correct 27 ms 6100 KB Output is correct
10 Correct 2 ms 3540 KB Output is correct
11 Correct 39 ms 7004 KB Output is correct
12 Correct 43 ms 7652 KB Output is correct
13 Correct 2 ms 3540 KB Output is correct
14 Correct 2 ms 3540 KB Output is correct
15 Correct 2 ms 3540 KB Output is correct
16 Correct 2 ms 3540 KB Output is correct
17 Correct 2 ms 3540 KB Output is correct
18 Correct 2 ms 3540 KB Output is correct
19 Correct 2 ms 3540 KB Output is correct
20 Correct 2 ms 3540 KB Output is correct
21 Correct 2 ms 3540 KB Output is correct
22 Correct 2 ms 3540 KB Output is correct
23 Correct 2 ms 3540 KB Output is correct
24 Correct 2 ms 3540 KB Output is correct
25 Correct 2 ms 3540 KB Output is correct
26 Correct 2 ms 3540 KB Output is correct
27 Correct 2 ms 3540 KB Output is correct
28 Correct 2 ms 3540 KB Output is correct
29 Correct 2 ms 3540 KB Output is correct
30 Correct 2 ms 3540 KB Output is correct
31 Correct 2 ms 3540 KB Output is correct
32 Correct 2 ms 3540 KB Output is correct
33 Correct 2 ms 3540 KB Output is correct
34 Correct 2 ms 3540 KB Output is correct
35 Correct 2 ms 3540 KB Output is correct
36 Correct 2 ms 3540 KB Output is correct
37 Correct 2 ms 3540 KB Output is correct
38 Correct 2 ms 3540 KB Output is correct
39 Correct 42 ms 8112 KB Output is correct
40 Correct 41 ms 8104 KB Output is correct
41 Correct 28 ms 6492 KB Output is correct
42 Correct 8 ms 4180 KB Output is correct
43 Correct 2 ms 3540 KB Output is correct
44 Correct 3 ms 3540 KB Output is correct
45 Correct 2 ms 3540 KB Output is correct
46 Correct 2 ms 3540 KB Output is correct
47 Correct 2 ms 3540 KB Output is correct
48 Correct 2 ms 3540 KB Output is correct
49 Correct 2 ms 3540 KB Output is correct
50 Correct 3 ms 3540 KB Output is correct
51 Correct 2 ms 3540 KB Output is correct
52 Correct 2 ms 3540 KB Output is correct
53 Correct 2 ms 3540 KB Output is correct
54 Correct 2 ms 3540 KB Output is correct
55 Correct 2 ms 3540 KB Output is correct
56 Correct 2 ms 3540 KB Output is correct
57 Correct 75 ms 9340 KB Output is correct
58 Correct 65 ms 9180 KB Output is correct
59 Correct 74 ms 9204 KB Output is correct
60 Correct 61 ms 8932 KB Output is correct
61 Correct 65 ms 9168 KB Output is correct
62 Correct 63 ms 8984 KB Output is correct
63 Correct 65 ms 9216 KB Output is correct
64 Correct 61 ms 9100 KB Output is correct
65 Correct 58 ms 9040 KB Output is correct
66 Correct 65 ms 9100 KB Output is correct
67 Correct 70 ms 9220 KB Output is correct
68 Correct 66 ms 9288 KB Output is correct
69 Correct 69 ms 8908 KB Output is correct
70 Correct 70 ms 8956 KB Output is correct
71 Correct 2 ms 3540 KB Output is correct
72 Correct 3 ms 3668 KB Output is correct
73 Correct 5 ms 3732 KB Output is correct
74 Correct 3 ms 3668 KB Output is correct
75 Correct 4 ms 3668 KB Output is correct
76 Correct 3 ms 3668 KB Output is correct
77 Correct 3 ms 3668 KB Output is correct
78 Correct 3 ms 3668 KB Output is correct
79 Correct 3 ms 3668 KB Output is correct
80 Correct 65 ms 9240 KB Output is correct
81 Correct 74 ms 9288 KB Output is correct
82 Correct 62 ms 9164 KB Output is correct
83 Correct 63 ms 9184 KB Output is correct
84 Correct 3 ms 3668 KB Output is correct
85 Correct 3 ms 3668 KB Output is correct
86 Correct 3 ms 3668 KB Output is correct
87 Correct 3 ms 3668 KB Output is correct
88 Correct 3 ms 3668 KB Output is correct
89 Correct 3 ms 3668 KB Output is correct
90 Correct 3 ms 3668 KB Output is correct
91 Correct 3 ms 3668 KB Output is correct
92 Correct 3 ms 3668 KB Output is correct
93 Correct 3 ms 3668 KB Output is correct
94 Correct 2 ms 3540 KB Output is correct
95 Correct 2 ms 3540 KB Output is correct
96 Correct 2 ms 3540 KB Output is correct
97 Correct 2 ms 3540 KB Output is correct
98 Correct 2 ms 3540 KB Output is correct
99 Correct 2 ms 3540 KB Output is correct
100 Correct 2 ms 3464 KB Output is correct
101 Correct 2 ms 3540 KB Output is correct
102 Correct 2 ms 3540 KB Output is correct
103 Correct 2 ms 3540 KB Output is correct
104 Correct 7 ms 4052 KB Output is correct
105 Correct 13 ms 4572 KB Output is correct
106 Correct 2 ms 3540 KB Output is correct
107 Correct 25 ms 5460 KB Output is correct
108 Correct 30 ms 6108 KB Output is correct
109 Correct 2 ms 3500 KB Output is correct
110 Correct 44 ms 6964 KB Output is correct
111 Correct 48 ms 7700 KB Output is correct
112 Correct 3 ms 3540 KB Output is correct
113 Correct 63 ms 8540 KB Output is correct
114 Execution timed out 1071 ms 6228 KB Time limit exceeded
115 Halted 0 ms 0 KB -