# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
830965 |
2023-08-19T13:52:40 Z |
Kerim |
Dreaming (IOI13_dreaming) |
C++17 |
|
69 ms |
12560 KB |
#include "dreaming.h"
#include "bits/stdc++.h"
using namespace std;
typedef pair<int, int> pii;
const int N = 1e5+5;
vector<pii> adj[N];
vector<int> members;
bool vis[N];
void dfs0(int nd, int pr){
vis[nd] = 1;
members.push_back(nd);
for (auto [to, w]: adj[nd])
if (to != pr)
dfs0(to, nd);
}
int max_weight, endpoint, dp[N];
void dfs(int nd, int pr, int weight){
if (weight > max_weight){
max_weight = weight;
endpoint = nd;
}
dp[nd] = max(dp[nd], weight);
for (auto [to, w]: adj[nd])
if (to != pr)
dfs(to, nd, weight+w);
}
int travelTime(int n, int m, int L, int A[], int B[], int T[]) {
for (int i = 0; i < m; i++){
int u = A[i], v = B[i], w = T[i];
adj[u].push_back({v, w});
adj[v].push_back({u, w});
}
vector<int> roots;
for (int i = 0; i < n; i++)
if (!vis[i]){
dfs0(i, -1);
roots.push_back(i);
}
vector<int> w;
int D = 0;
for (auto root: roots){
members.clear();
dfs0(root, -1);
max_weight = 0;
dfs(root, -1, 0);
int a = endpoint;
max_weight = 0;
dfs(endpoint, -1, 0);
int b = endpoint;
D = max(D, max_weight);
dfs(a, -1, 0);
dfs(b, -1, 0);
int value = INT_MAX;
for (auto member: members)
if (value > dp[member])
value = dp[member];
w.push_back(value);
}
sort(w.rbegin(), w.rend());
int c = roots.size();
int answer = D;
if (c >= 2)
answer = max(answer, w[0] + w[1] + L);
if (c >= 3)
answer = max(answer, w[0] + w[2] + 2*L);
return answer;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
11860 KB |
Output is correct |
2 |
Correct |
36 ms |
11744 KB |
Output is correct |
3 |
Correct |
24 ms |
8576 KB |
Output is correct |
4 |
Correct |
6 ms |
4052 KB |
Output is correct |
5 |
Correct |
5 ms |
3496 KB |
Output is correct |
6 |
Correct |
11 ms |
4712 KB |
Output is correct |
7 |
Correct |
1 ms |
2644 KB |
Output is correct |
8 |
Correct |
20 ms |
6004 KB |
Output is correct |
9 |
Correct |
26 ms |
7252 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
11 |
Correct |
37 ms |
8584 KB |
Output is correct |
12 |
Correct |
41 ms |
10172 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 ms |
2644 KB |
Output is correct |
7 |
Correct |
1 ms |
2644 KB |
Output is correct |
8 |
Correct |
1 ms |
2644 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
11 |
Correct |
1 ms |
2644 KB |
Output is correct |
12 |
Correct |
1 ms |
2644 KB |
Output is correct |
13 |
Correct |
1 ms |
2612 KB |
Output is correct |
14 |
Correct |
1 ms |
2636 KB |
Output is correct |
15 |
Correct |
1 ms |
2644 KB |
Output is correct |
16 |
Correct |
1 ms |
2644 KB |
Output is correct |
17 |
Correct |
1 ms |
2644 KB |
Output is correct |
18 |
Correct |
1 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
2644 KB |
Output is correct |
20 |
Correct |
1 ms |
2644 KB |
Output is correct |
21 |
Correct |
1 ms |
2644 KB |
Output is correct |
22 |
Correct |
1 ms |
2644 KB |
Output is correct |
23 |
Correct |
1 ms |
2644 KB |
Output is correct |
24 |
Correct |
1 ms |
2644 KB |
Output is correct |
25 |
Correct |
1 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
11860 KB |
Output is correct |
2 |
Correct |
36 ms |
11744 KB |
Output is correct |
3 |
Correct |
24 ms |
8576 KB |
Output is correct |
4 |
Correct |
6 ms |
4052 KB |
Output is correct |
5 |
Correct |
5 ms |
3496 KB |
Output is correct |
6 |
Correct |
11 ms |
4712 KB |
Output is correct |
7 |
Correct |
1 ms |
2644 KB |
Output is correct |
8 |
Correct |
20 ms |
6004 KB |
Output is correct |
9 |
Correct |
26 ms |
7252 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
11 |
Correct |
37 ms |
8584 KB |
Output is correct |
12 |
Correct |
41 ms |
10172 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
1 ms |
2644 KB |
Output is correct |
16 |
Correct |
1 ms |
2644 KB |
Output is correct |
17 |
Correct |
1 ms |
2644 KB |
Output is correct |
18 |
Correct |
2 ms |
2644 KB |
Output is correct |
19 |
Correct |
1 ms |
2644 KB |
Output is correct |
20 |
Correct |
1 ms |
2644 KB |
Output is correct |
21 |
Correct |
1 ms |
2644 KB |
Output is correct |
22 |
Correct |
1 ms |
2644 KB |
Output is correct |
23 |
Correct |
1 ms |
2644 KB |
Output is correct |
24 |
Correct |
1 ms |
2644 KB |
Output is correct |
25 |
Correct |
1 ms |
2644 KB |
Output is correct |
26 |
Correct |
1 ms |
2612 KB |
Output is correct |
27 |
Correct |
1 ms |
2636 KB |
Output is correct |
28 |
Correct |
1 ms |
2644 KB |
Output is correct |
29 |
Correct |
1 ms |
2644 KB |
Output is correct |
30 |
Correct |
1 ms |
2644 KB |
Output is correct |
31 |
Correct |
1 ms |
2644 KB |
Output is correct |
32 |
Correct |
2 ms |
2644 KB |
Output is correct |
33 |
Correct |
1 ms |
2644 KB |
Output is correct |
34 |
Correct |
1 ms |
2644 KB |
Output is correct |
35 |
Correct |
1 ms |
2644 KB |
Output is correct |
36 |
Correct |
1 ms |
2644 KB |
Output is correct |
37 |
Correct |
1 ms |
2644 KB |
Output is correct |
38 |
Correct |
1 ms |
2644 KB |
Output is correct |
39 |
Correct |
36 ms |
11780 KB |
Output is correct |
40 |
Correct |
35 ms |
11704 KB |
Output is correct |
41 |
Correct |
26 ms |
8680 KB |
Output is correct |
42 |
Correct |
6 ms |
4052 KB |
Output is correct |
43 |
Correct |
1 ms |
2644 KB |
Output is correct |
44 |
Correct |
1 ms |
2644 KB |
Output is correct |
45 |
Correct |
1 ms |
2644 KB |
Output is correct |
46 |
Correct |
1 ms |
2644 KB |
Output is correct |
47 |
Correct |
1 ms |
2644 KB |
Output is correct |
48 |
Correct |
1 ms |
2644 KB |
Output is correct |
49 |
Correct |
1 ms |
2644 KB |
Output is correct |
50 |
Correct |
1 ms |
2644 KB |
Output is correct |
51 |
Correct |
1 ms |
2644 KB |
Output is correct |
52 |
Correct |
1 ms |
2644 KB |
Output is correct |
53 |
Correct |
1 ms |
2644 KB |
Output is correct |
54 |
Correct |
1 ms |
2644 KB |
Output is correct |
55 |
Correct |
1 ms |
2644 KB |
Output is correct |
56 |
Correct |
1 ms |
2644 KB |
Output is correct |
57 |
Correct |
49 ms |
8816 KB |
Output is correct |
58 |
Correct |
47 ms |
8776 KB |
Output is correct |
59 |
Correct |
49 ms |
8728 KB |
Output is correct |
60 |
Correct |
60 ms |
8668 KB |
Output is correct |
61 |
Correct |
46 ms |
8560 KB |
Output is correct |
62 |
Correct |
47 ms |
8660 KB |
Output is correct |
63 |
Correct |
44 ms |
8376 KB |
Output is correct |
64 |
Correct |
51 ms |
8384 KB |
Output is correct |
65 |
Correct |
44 ms |
8388 KB |
Output is correct |
66 |
Correct |
45 ms |
8492 KB |
Output is correct |
67 |
Correct |
49 ms |
8656 KB |
Output is correct |
68 |
Correct |
49 ms |
8712 KB |
Output is correct |
69 |
Correct |
58 ms |
8704 KB |
Output is correct |
70 |
Correct |
50 ms |
8696 KB |
Output is correct |
71 |
Correct |
1 ms |
2644 KB |
Output is correct |
72 |
Correct |
4 ms |
2772 KB |
Output is correct |
73 |
Correct |
2 ms |
2772 KB |
Output is correct |
74 |
Correct |
2 ms |
2772 KB |
Output is correct |
75 |
Correct |
2 ms |
2772 KB |
Output is correct |
76 |
Correct |
2 ms |
2772 KB |
Output is correct |
77 |
Correct |
2 ms |
2772 KB |
Output is correct |
78 |
Correct |
2 ms |
2772 KB |
Output is correct |
79 |
Correct |
2 ms |
2772 KB |
Output is correct |
80 |
Correct |
49 ms |
8652 KB |
Output is correct |
81 |
Correct |
49 ms |
8692 KB |
Output is correct |
82 |
Correct |
45 ms |
8568 KB |
Output is correct |
83 |
Correct |
62 ms |
8752 KB |
Output is correct |
84 |
Correct |
2 ms |
2772 KB |
Output is correct |
85 |
Correct |
2 ms |
2772 KB |
Output is correct |
86 |
Correct |
2 ms |
2772 KB |
Output is correct |
87 |
Correct |
2 ms |
2772 KB |
Output is correct |
88 |
Correct |
2 ms |
2772 KB |
Output is correct |
89 |
Correct |
2 ms |
2772 KB |
Output is correct |
90 |
Correct |
2 ms |
2772 KB |
Output is correct |
91 |
Correct |
2 ms |
2772 KB |
Output is correct |
92 |
Correct |
2 ms |
2772 KB |
Output is correct |
93 |
Correct |
2 ms |
2772 KB |
Output is correct |
94 |
Correct |
1 ms |
2644 KB |
Output is correct |
95 |
Correct |
1 ms |
2644 KB |
Output is correct |
96 |
Correct |
1 ms |
2644 KB |
Output is correct |
97 |
Correct |
1 ms |
2644 KB |
Output is correct |
98 |
Correct |
1 ms |
2644 KB |
Output is correct |
99 |
Correct |
1 ms |
2644 KB |
Output is correct |
100 |
Correct |
1 ms |
2644 KB |
Output is correct |
101 |
Correct |
1 ms |
2644 KB |
Output is correct |
102 |
Correct |
1 ms |
2644 KB |
Output is correct |
103 |
Correct |
1 ms |
2644 KB |
Output is correct |
104 |
Correct |
6 ms |
3412 KB |
Output is correct |
105 |
Correct |
12 ms |
4692 KB |
Output is correct |
106 |
Correct |
1 ms |
2644 KB |
Output is correct |
107 |
Correct |
21 ms |
5980 KB |
Output is correct |
108 |
Correct |
26 ms |
7156 KB |
Output is correct |
109 |
Correct |
2 ms |
2644 KB |
Output is correct |
110 |
Correct |
39 ms |
8656 KB |
Output is correct |
111 |
Correct |
42 ms |
10076 KB |
Output is correct |
112 |
Correct |
1 ms |
2644 KB |
Output is correct |
113 |
Correct |
69 ms |
12560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
6476 KB |
Output is correct |
2 |
Incorrect |
16 ms |
7000 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 ms |
2644 KB |
Output is correct |
7 |
Correct |
1 ms |
2644 KB |
Output is correct |
8 |
Correct |
1 ms |
2644 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
11 |
Correct |
1 ms |
2644 KB |
Output is correct |
12 |
Correct |
1 ms |
2644 KB |
Output is correct |
13 |
Correct |
1 ms |
2612 KB |
Output is correct |
14 |
Correct |
1 ms |
2636 KB |
Output is correct |
15 |
Correct |
1 ms |
2644 KB |
Output is correct |
16 |
Correct |
1 ms |
2644 KB |
Output is correct |
17 |
Correct |
1 ms |
2644 KB |
Output is correct |
18 |
Correct |
1 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
2644 KB |
Output is correct |
20 |
Correct |
1 ms |
2644 KB |
Output is correct |
21 |
Correct |
1 ms |
2644 KB |
Output is correct |
22 |
Correct |
1 ms |
2644 KB |
Output is correct |
23 |
Correct |
1 ms |
2644 KB |
Output is correct |
24 |
Correct |
1 ms |
2644 KB |
Output is correct |
25 |
Correct |
1 ms |
2644 KB |
Output is correct |
26 |
Correct |
1 ms |
2644 KB |
Output is correct |
27 |
Correct |
2 ms |
2772 KB |
Output is correct |
28 |
Correct |
2 ms |
2772 KB |
Output is correct |
29 |
Correct |
1 ms |
2644 KB |
Output is correct |
30 |
Correct |
2 ms |
2772 KB |
Output is correct |
31 |
Correct |
2 ms |
2796 KB |
Output is correct |
32 |
Incorrect |
2 ms |
2664 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
11860 KB |
Output is correct |
2 |
Correct |
36 ms |
11744 KB |
Output is correct |
3 |
Correct |
24 ms |
8576 KB |
Output is correct |
4 |
Correct |
6 ms |
4052 KB |
Output is correct |
5 |
Correct |
5 ms |
3496 KB |
Output is correct |
6 |
Correct |
11 ms |
4712 KB |
Output is correct |
7 |
Correct |
1 ms |
2644 KB |
Output is correct |
8 |
Correct |
20 ms |
6004 KB |
Output is correct |
9 |
Correct |
26 ms |
7252 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
11 |
Correct |
37 ms |
8584 KB |
Output is correct |
12 |
Correct |
41 ms |
10172 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
1 ms |
2644 KB |
Output is correct |
16 |
Correct |
1 ms |
2644 KB |
Output is correct |
17 |
Correct |
1 ms |
2644 KB |
Output is correct |
18 |
Correct |
2 ms |
2644 KB |
Output is correct |
19 |
Correct |
1 ms |
2644 KB |
Output is correct |
20 |
Correct |
1 ms |
2644 KB |
Output is correct |
21 |
Correct |
1 ms |
2644 KB |
Output is correct |
22 |
Correct |
1 ms |
2644 KB |
Output is correct |
23 |
Correct |
1 ms |
2644 KB |
Output is correct |
24 |
Correct |
1 ms |
2644 KB |
Output is correct |
25 |
Correct |
1 ms |
2644 KB |
Output is correct |
26 |
Correct |
1 ms |
2612 KB |
Output is correct |
27 |
Correct |
1 ms |
2636 KB |
Output is correct |
28 |
Correct |
1 ms |
2644 KB |
Output is correct |
29 |
Correct |
1 ms |
2644 KB |
Output is correct |
30 |
Correct |
1 ms |
2644 KB |
Output is correct |
31 |
Correct |
1 ms |
2644 KB |
Output is correct |
32 |
Correct |
2 ms |
2644 KB |
Output is correct |
33 |
Correct |
1 ms |
2644 KB |
Output is correct |
34 |
Correct |
1 ms |
2644 KB |
Output is correct |
35 |
Correct |
1 ms |
2644 KB |
Output is correct |
36 |
Correct |
1 ms |
2644 KB |
Output is correct |
37 |
Correct |
1 ms |
2644 KB |
Output is correct |
38 |
Correct |
1 ms |
2644 KB |
Output is correct |
39 |
Correct |
36 ms |
11780 KB |
Output is correct |
40 |
Correct |
35 ms |
11704 KB |
Output is correct |
41 |
Correct |
26 ms |
8680 KB |
Output is correct |
42 |
Correct |
6 ms |
4052 KB |
Output is correct |
43 |
Correct |
1 ms |
2644 KB |
Output is correct |
44 |
Correct |
1 ms |
2644 KB |
Output is correct |
45 |
Correct |
1 ms |
2644 KB |
Output is correct |
46 |
Correct |
1 ms |
2644 KB |
Output is correct |
47 |
Correct |
1 ms |
2644 KB |
Output is correct |
48 |
Correct |
1 ms |
2644 KB |
Output is correct |
49 |
Correct |
1 ms |
2644 KB |
Output is correct |
50 |
Correct |
1 ms |
2644 KB |
Output is correct |
51 |
Correct |
1 ms |
2644 KB |
Output is correct |
52 |
Correct |
1 ms |
2644 KB |
Output is correct |
53 |
Correct |
1 ms |
2644 KB |
Output is correct |
54 |
Correct |
1 ms |
2644 KB |
Output is correct |
55 |
Correct |
1 ms |
2644 KB |
Output is correct |
56 |
Correct |
1 ms |
2644 KB |
Output is correct |
57 |
Correct |
49 ms |
8816 KB |
Output is correct |
58 |
Correct |
47 ms |
8776 KB |
Output is correct |
59 |
Correct |
49 ms |
8728 KB |
Output is correct |
60 |
Correct |
60 ms |
8668 KB |
Output is correct |
61 |
Correct |
46 ms |
8560 KB |
Output is correct |
62 |
Correct |
47 ms |
8660 KB |
Output is correct |
63 |
Correct |
44 ms |
8376 KB |
Output is correct |
64 |
Correct |
51 ms |
8384 KB |
Output is correct |
65 |
Correct |
44 ms |
8388 KB |
Output is correct |
66 |
Correct |
45 ms |
8492 KB |
Output is correct |
67 |
Correct |
49 ms |
8656 KB |
Output is correct |
68 |
Correct |
49 ms |
8712 KB |
Output is correct |
69 |
Correct |
58 ms |
8704 KB |
Output is correct |
70 |
Correct |
50 ms |
8696 KB |
Output is correct |
71 |
Correct |
1 ms |
2644 KB |
Output is correct |
72 |
Correct |
4 ms |
2772 KB |
Output is correct |
73 |
Correct |
2 ms |
2772 KB |
Output is correct |
74 |
Correct |
2 ms |
2772 KB |
Output is correct |
75 |
Correct |
2 ms |
2772 KB |
Output is correct |
76 |
Correct |
2 ms |
2772 KB |
Output is correct |
77 |
Correct |
2 ms |
2772 KB |
Output is correct |
78 |
Correct |
2 ms |
2772 KB |
Output is correct |
79 |
Correct |
2 ms |
2772 KB |
Output is correct |
80 |
Correct |
49 ms |
8652 KB |
Output is correct |
81 |
Correct |
49 ms |
8692 KB |
Output is correct |
82 |
Correct |
45 ms |
8568 KB |
Output is correct |
83 |
Correct |
62 ms |
8752 KB |
Output is correct |
84 |
Correct |
2 ms |
2772 KB |
Output is correct |
85 |
Correct |
2 ms |
2772 KB |
Output is correct |
86 |
Correct |
2 ms |
2772 KB |
Output is correct |
87 |
Correct |
2 ms |
2772 KB |
Output is correct |
88 |
Correct |
2 ms |
2772 KB |
Output is correct |
89 |
Correct |
2 ms |
2772 KB |
Output is correct |
90 |
Correct |
2 ms |
2772 KB |
Output is correct |
91 |
Correct |
2 ms |
2772 KB |
Output is correct |
92 |
Correct |
2 ms |
2772 KB |
Output is correct |
93 |
Correct |
2 ms |
2772 KB |
Output is correct |
94 |
Correct |
1 ms |
2644 KB |
Output is correct |
95 |
Correct |
1 ms |
2644 KB |
Output is correct |
96 |
Correct |
1 ms |
2644 KB |
Output is correct |
97 |
Correct |
1 ms |
2644 KB |
Output is correct |
98 |
Correct |
1 ms |
2644 KB |
Output is correct |
99 |
Correct |
1 ms |
2644 KB |
Output is correct |
100 |
Correct |
1 ms |
2644 KB |
Output is correct |
101 |
Correct |
1 ms |
2644 KB |
Output is correct |
102 |
Correct |
1 ms |
2644 KB |
Output is correct |
103 |
Correct |
1 ms |
2644 KB |
Output is correct |
104 |
Correct |
6 ms |
3412 KB |
Output is correct |
105 |
Correct |
12 ms |
4692 KB |
Output is correct |
106 |
Correct |
1 ms |
2644 KB |
Output is correct |
107 |
Correct |
21 ms |
5980 KB |
Output is correct |
108 |
Correct |
26 ms |
7156 KB |
Output is correct |
109 |
Correct |
2 ms |
2644 KB |
Output is correct |
110 |
Correct |
39 ms |
8656 KB |
Output is correct |
111 |
Correct |
42 ms |
10076 KB |
Output is correct |
112 |
Correct |
1 ms |
2644 KB |
Output is correct |
113 |
Correct |
69 ms |
12560 KB |
Output is correct |
114 |
Correct |
16 ms |
6476 KB |
Output is correct |
115 |
Incorrect |
16 ms |
7000 KB |
Output isn't correct |
116 |
Halted |
0 ms |
0 KB |
- |