# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1043784 |
2024-08-04T17:18:57 Z |
vanea |
Dreaming (IOI13_dreaming) |
C++14 |
|
37 ms |
18044 KB |
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
using ll = long long;
using ld = long double;
const int mxN = 1e5+10;
vector<array<int, 2>> adj[mxN];
bool vis[mxN];
ll ans = 0, mx1 = 0, mx2 = 0, mx_1[mxN], mx_2[mxN];
ll dfs(int node, int p) {
ll mx1 = 0, mx2 = 0;
vis[node] = true;
for(auto [it, w] : adj[node]) {
if(it == p) continue;
mx2 = max(mx2, dfs(it, node)+w);
if(mx2 > mx1) swap(mx1, mx2);
}
ans = max(ans, mx2+mx1);
mx_1[node] = mx1;
mx_2[node] = mx2;
return mx1;
}
ll dfs1(int node, int p) {
ll mn = mx_1[node];
vis[node] = true;
for(auto [it, w] : adj[node]) {
if(it == p) continue;
if(mx_1[node]-w == mx_1[it]) {
mx_2[it] = max(mx_2[it], mx_2[node]+w);
if(mx_2[it] > mx_1[it]) swap(mx_2[it], mx_1[it]);
}
else {
int init = mx_1[it];
mx_2[it] = max(mx_2[it], mx_1[node]+w);
if(mx_2[it] > mx_1[it]) swap(mx_2[it], mx_1[it]);
if(mx_2[node]-w != init) {
mx_2[it] = max(mx_2[it], mx_2[node]+w);
}
}
mn = min(mn, dfs1(it, node));
}
return mn;
}
int travelTime(int n, int m, int l, int a[], int b[], int t[]) {
for(int i = 0; i < m; i++) {
adj[a[i]].push_back({b[i], t[i]});
adj[b[i]].push_back({a[i], t[i]});
}
for(int i = 0; i < n; i++) {
if(!vis[i]) dfs(i, -1);
}
if(m == n-1) return ans;
memset(vis, false, sizeof vis);
for(int i = 0; i < n; i++) {
if(!vis[i]) {
mx2 = max(mx2, dfs1(i, -1));
if(mx2 > mx1) swap(mx1, mx2);
}
}
return max(ans, mx1+mx2+l);
}
/*
int main()
{
int a[8] = {0,8,2,5,5,1,1,10};
int b[8] = {8,2,7,11,1,3,9,6};
int c[8] = {4,2,4,3,7,1,5,3};
cout << travelTime(12, 8, 2, a, b, c);
}*/
Compilation message
dreaming.cpp: In function 'll dfs(int, int)':
dreaming.cpp:16:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
16 | for(auto [it, w] : adj[node]) {
| ^
dreaming.cpp: In function 'll dfs1(int, int)':
dreaming.cpp:30:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
30 | for(auto [it, w] : adj[node]) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
12380 KB |
Output is correct |
2 |
Correct |
28 ms |
11920 KB |
Output is correct |
3 |
Correct |
15 ms |
11356 KB |
Output is correct |
4 |
Correct |
4 ms |
6260 KB |
Output is correct |
5 |
Correct |
3 ms |
5980 KB |
Output is correct |
6 |
Correct |
7 ms |
7004 KB |
Output is correct |
7 |
Correct |
1 ms |
5212 KB |
Output is correct |
8 |
Correct |
13 ms |
8860 KB |
Output is correct |
9 |
Correct |
16 ms |
10904 KB |
Output is correct |
10 |
Correct |
1 ms |
5464 KB |
Output is correct |
11 |
Correct |
24 ms |
11448 KB |
Output is correct |
12 |
Correct |
31 ms |
12456 KB |
Output is correct |
13 |
Correct |
1 ms |
5464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5212 KB |
Output is correct |
2 |
Correct |
1 ms |
5212 KB |
Output is correct |
3 |
Correct |
1 ms |
5208 KB |
Output is correct |
4 |
Correct |
1 ms |
5212 KB |
Output is correct |
5 |
Correct |
2 ms |
5212 KB |
Output is correct |
6 |
Correct |
1 ms |
5212 KB |
Output is correct |
7 |
Correct |
1 ms |
5212 KB |
Output is correct |
8 |
Correct |
1 ms |
5212 KB |
Output is correct |
9 |
Correct |
1 ms |
5212 KB |
Output is correct |
10 |
Correct |
1 ms |
5444 KB |
Output is correct |
11 |
Correct |
1 ms |
5212 KB |
Output is correct |
12 |
Correct |
1 ms |
5208 KB |
Output is correct |
13 |
Correct |
1 ms |
5464 KB |
Output is correct |
14 |
Correct |
1 ms |
5208 KB |
Output is correct |
15 |
Correct |
1 ms |
5212 KB |
Output is correct |
16 |
Correct |
1 ms |
5212 KB |
Output is correct |
17 |
Correct |
1 ms |
5448 KB |
Output is correct |
18 |
Correct |
1 ms |
5212 KB |
Output is correct |
19 |
Correct |
1 ms |
5212 KB |
Output is correct |
20 |
Correct |
1 ms |
5212 KB |
Output is correct |
21 |
Correct |
1 ms |
5212 KB |
Output is correct |
22 |
Correct |
1 ms |
5208 KB |
Output is correct |
23 |
Correct |
1 ms |
5212 KB |
Output is correct |
24 |
Correct |
1 ms |
5212 KB |
Output is correct |
25 |
Correct |
1 ms |
5212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
12380 KB |
Output is correct |
2 |
Correct |
28 ms |
11920 KB |
Output is correct |
3 |
Correct |
15 ms |
11356 KB |
Output is correct |
4 |
Correct |
4 ms |
6260 KB |
Output is correct |
5 |
Correct |
3 ms |
5980 KB |
Output is correct |
6 |
Correct |
7 ms |
7004 KB |
Output is correct |
7 |
Correct |
1 ms |
5212 KB |
Output is correct |
8 |
Correct |
13 ms |
8860 KB |
Output is correct |
9 |
Correct |
16 ms |
10904 KB |
Output is correct |
10 |
Correct |
1 ms |
5464 KB |
Output is correct |
11 |
Correct |
24 ms |
11448 KB |
Output is correct |
12 |
Correct |
31 ms |
12456 KB |
Output is correct |
13 |
Correct |
1 ms |
5464 KB |
Output is correct |
14 |
Correct |
1 ms |
5212 KB |
Output is correct |
15 |
Correct |
1 ms |
5212 KB |
Output is correct |
16 |
Correct |
1 ms |
5208 KB |
Output is correct |
17 |
Correct |
1 ms |
5212 KB |
Output is correct |
18 |
Correct |
2 ms |
5212 KB |
Output is correct |
19 |
Correct |
1 ms |
5212 KB |
Output is correct |
20 |
Correct |
1 ms |
5212 KB |
Output is correct |
21 |
Correct |
1 ms |
5212 KB |
Output is correct |
22 |
Correct |
1 ms |
5212 KB |
Output is correct |
23 |
Correct |
1 ms |
5444 KB |
Output is correct |
24 |
Correct |
1 ms |
5212 KB |
Output is correct |
25 |
Correct |
1 ms |
5208 KB |
Output is correct |
26 |
Correct |
1 ms |
5464 KB |
Output is correct |
27 |
Correct |
1 ms |
5208 KB |
Output is correct |
28 |
Correct |
1 ms |
5212 KB |
Output is correct |
29 |
Correct |
1 ms |
5212 KB |
Output is correct |
30 |
Correct |
1 ms |
5448 KB |
Output is correct |
31 |
Correct |
1 ms |
5212 KB |
Output is correct |
32 |
Correct |
1 ms |
5212 KB |
Output is correct |
33 |
Correct |
1 ms |
5212 KB |
Output is correct |
34 |
Correct |
1 ms |
5212 KB |
Output is correct |
35 |
Correct |
1 ms |
5208 KB |
Output is correct |
36 |
Correct |
1 ms |
5212 KB |
Output is correct |
37 |
Correct |
1 ms |
5212 KB |
Output is correct |
38 |
Correct |
1 ms |
5212 KB |
Output is correct |
39 |
Correct |
26 ms |
13660 KB |
Output is correct |
40 |
Correct |
26 ms |
13280 KB |
Output is correct |
41 |
Correct |
18 ms |
12412 KB |
Output is correct |
42 |
Correct |
4 ms |
6560 KB |
Output is correct |
43 |
Correct |
2 ms |
5208 KB |
Output is correct |
44 |
Correct |
2 ms |
5464 KB |
Output is correct |
45 |
Correct |
1 ms |
5212 KB |
Output is correct |
46 |
Correct |
1 ms |
5208 KB |
Output is correct |
47 |
Correct |
1 ms |
5212 KB |
Output is correct |
48 |
Correct |
1 ms |
5212 KB |
Output is correct |
49 |
Correct |
1 ms |
5212 KB |
Output is correct |
50 |
Correct |
2 ms |
5212 KB |
Output is correct |
51 |
Correct |
1 ms |
5212 KB |
Output is correct |
52 |
Correct |
1 ms |
5212 KB |
Output is correct |
53 |
Correct |
1 ms |
5212 KB |
Output is correct |
54 |
Correct |
1 ms |
5212 KB |
Output is correct |
55 |
Correct |
1 ms |
5208 KB |
Output is correct |
56 |
Correct |
1 ms |
5444 KB |
Output is correct |
57 |
Correct |
29 ms |
10832 KB |
Output is correct |
58 |
Correct |
30 ms |
10836 KB |
Output is correct |
59 |
Correct |
28 ms |
10836 KB |
Output is correct |
60 |
Correct |
30 ms |
10836 KB |
Output is correct |
61 |
Correct |
28 ms |
10832 KB |
Output is correct |
62 |
Correct |
27 ms |
10836 KB |
Output is correct |
63 |
Correct |
26 ms |
10576 KB |
Output is correct |
64 |
Correct |
30 ms |
10580 KB |
Output is correct |
65 |
Correct |
27 ms |
10844 KB |
Output is correct |
66 |
Correct |
30 ms |
10716 KB |
Output is correct |
67 |
Correct |
29 ms |
10836 KB |
Output is correct |
68 |
Correct |
29 ms |
10832 KB |
Output is correct |
69 |
Correct |
36 ms |
10968 KB |
Output is correct |
70 |
Correct |
29 ms |
11088 KB |
Output is correct |
71 |
Correct |
1 ms |
5212 KB |
Output is correct |
72 |
Correct |
2 ms |
5488 KB |
Output is correct |
73 |
Correct |
1 ms |
5484 KB |
Output is correct |
74 |
Correct |
2 ms |
5468 KB |
Output is correct |
75 |
Correct |
2 ms |
5468 KB |
Output is correct |
76 |
Correct |
2 ms |
5468 KB |
Output is correct |
77 |
Correct |
2 ms |
5468 KB |
Output is correct |
78 |
Correct |
1 ms |
5620 KB |
Output is correct |
79 |
Correct |
1 ms |
5468 KB |
Output is correct |
80 |
Correct |
31 ms |
10844 KB |
Output is correct |
81 |
Correct |
31 ms |
10860 KB |
Output is correct |
82 |
Correct |
29 ms |
10836 KB |
Output is correct |
83 |
Correct |
33 ms |
11004 KB |
Output is correct |
84 |
Correct |
1 ms |
5468 KB |
Output is correct |
85 |
Correct |
1 ms |
5468 KB |
Output is correct |
86 |
Correct |
1 ms |
5456 KB |
Output is correct |
87 |
Correct |
1 ms |
5468 KB |
Output is correct |
88 |
Correct |
1 ms |
5508 KB |
Output is correct |
89 |
Correct |
2 ms |
5468 KB |
Output is correct |
90 |
Correct |
1 ms |
5468 KB |
Output is correct |
91 |
Correct |
2 ms |
5468 KB |
Output is correct |
92 |
Correct |
2 ms |
5468 KB |
Output is correct |
93 |
Correct |
1 ms |
5468 KB |
Output is correct |
94 |
Correct |
1 ms |
5212 KB |
Output is correct |
95 |
Correct |
1 ms |
5212 KB |
Output is correct |
96 |
Correct |
1 ms |
5212 KB |
Output is correct |
97 |
Correct |
1 ms |
5440 KB |
Output is correct |
98 |
Correct |
1 ms |
5440 KB |
Output is correct |
99 |
Correct |
1 ms |
5212 KB |
Output is correct |
100 |
Correct |
1 ms |
5212 KB |
Output is correct |
101 |
Correct |
1 ms |
5212 KB |
Output is correct |
102 |
Correct |
1 ms |
5212 KB |
Output is correct |
103 |
Correct |
1 ms |
5212 KB |
Output is correct |
104 |
Correct |
3 ms |
5980 KB |
Output is correct |
105 |
Correct |
7 ms |
7260 KB |
Output is correct |
106 |
Correct |
1 ms |
5468 KB |
Output is correct |
107 |
Correct |
12 ms |
8900 KB |
Output is correct |
108 |
Correct |
16 ms |
10860 KB |
Output is correct |
109 |
Correct |
1 ms |
5468 KB |
Output is correct |
110 |
Correct |
22 ms |
11356 KB |
Output is correct |
111 |
Correct |
27 ms |
12468 KB |
Output is correct |
112 |
Correct |
1 ms |
5468 KB |
Output is correct |
113 |
Correct |
37 ms |
18044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
7516 KB |
Output is correct |
2 |
Incorrect |
9 ms |
7516 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5212 KB |
Output is correct |
2 |
Correct |
1 ms |
5212 KB |
Output is correct |
3 |
Correct |
1 ms |
5208 KB |
Output is correct |
4 |
Correct |
1 ms |
5212 KB |
Output is correct |
5 |
Correct |
2 ms |
5212 KB |
Output is correct |
6 |
Correct |
1 ms |
5212 KB |
Output is correct |
7 |
Correct |
1 ms |
5212 KB |
Output is correct |
8 |
Correct |
1 ms |
5212 KB |
Output is correct |
9 |
Correct |
1 ms |
5212 KB |
Output is correct |
10 |
Correct |
1 ms |
5444 KB |
Output is correct |
11 |
Correct |
1 ms |
5212 KB |
Output is correct |
12 |
Correct |
1 ms |
5208 KB |
Output is correct |
13 |
Correct |
1 ms |
5464 KB |
Output is correct |
14 |
Correct |
1 ms |
5208 KB |
Output is correct |
15 |
Correct |
1 ms |
5212 KB |
Output is correct |
16 |
Correct |
1 ms |
5212 KB |
Output is correct |
17 |
Correct |
1 ms |
5448 KB |
Output is correct |
18 |
Correct |
1 ms |
5212 KB |
Output is correct |
19 |
Correct |
1 ms |
5212 KB |
Output is correct |
20 |
Correct |
1 ms |
5212 KB |
Output is correct |
21 |
Correct |
1 ms |
5212 KB |
Output is correct |
22 |
Correct |
1 ms |
5208 KB |
Output is correct |
23 |
Correct |
1 ms |
5212 KB |
Output is correct |
24 |
Correct |
1 ms |
5212 KB |
Output is correct |
25 |
Correct |
1 ms |
5212 KB |
Output is correct |
26 |
Correct |
1 ms |
5472 KB |
Output is correct |
27 |
Correct |
1 ms |
5296 KB |
Output is correct |
28 |
Correct |
1 ms |
5468 KB |
Output is correct |
29 |
Correct |
1 ms |
5468 KB |
Output is correct |
30 |
Correct |
1 ms |
5468 KB |
Output is correct |
31 |
Correct |
1 ms |
5468 KB |
Output is correct |
32 |
Incorrect |
1 ms |
5456 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
12380 KB |
Output is correct |
2 |
Correct |
28 ms |
11920 KB |
Output is correct |
3 |
Correct |
15 ms |
11356 KB |
Output is correct |
4 |
Correct |
4 ms |
6260 KB |
Output is correct |
5 |
Correct |
3 ms |
5980 KB |
Output is correct |
6 |
Correct |
7 ms |
7004 KB |
Output is correct |
7 |
Correct |
1 ms |
5212 KB |
Output is correct |
8 |
Correct |
13 ms |
8860 KB |
Output is correct |
9 |
Correct |
16 ms |
10904 KB |
Output is correct |
10 |
Correct |
1 ms |
5464 KB |
Output is correct |
11 |
Correct |
24 ms |
11448 KB |
Output is correct |
12 |
Correct |
31 ms |
12456 KB |
Output is correct |
13 |
Correct |
1 ms |
5464 KB |
Output is correct |
14 |
Correct |
1 ms |
5212 KB |
Output is correct |
15 |
Correct |
1 ms |
5212 KB |
Output is correct |
16 |
Correct |
1 ms |
5208 KB |
Output is correct |
17 |
Correct |
1 ms |
5212 KB |
Output is correct |
18 |
Correct |
2 ms |
5212 KB |
Output is correct |
19 |
Correct |
1 ms |
5212 KB |
Output is correct |
20 |
Correct |
1 ms |
5212 KB |
Output is correct |
21 |
Correct |
1 ms |
5212 KB |
Output is correct |
22 |
Correct |
1 ms |
5212 KB |
Output is correct |
23 |
Correct |
1 ms |
5444 KB |
Output is correct |
24 |
Correct |
1 ms |
5212 KB |
Output is correct |
25 |
Correct |
1 ms |
5208 KB |
Output is correct |
26 |
Correct |
1 ms |
5464 KB |
Output is correct |
27 |
Correct |
1 ms |
5208 KB |
Output is correct |
28 |
Correct |
1 ms |
5212 KB |
Output is correct |
29 |
Correct |
1 ms |
5212 KB |
Output is correct |
30 |
Correct |
1 ms |
5448 KB |
Output is correct |
31 |
Correct |
1 ms |
5212 KB |
Output is correct |
32 |
Correct |
1 ms |
5212 KB |
Output is correct |
33 |
Correct |
1 ms |
5212 KB |
Output is correct |
34 |
Correct |
1 ms |
5212 KB |
Output is correct |
35 |
Correct |
1 ms |
5208 KB |
Output is correct |
36 |
Correct |
1 ms |
5212 KB |
Output is correct |
37 |
Correct |
1 ms |
5212 KB |
Output is correct |
38 |
Correct |
1 ms |
5212 KB |
Output is correct |
39 |
Correct |
26 ms |
13660 KB |
Output is correct |
40 |
Correct |
26 ms |
13280 KB |
Output is correct |
41 |
Correct |
18 ms |
12412 KB |
Output is correct |
42 |
Correct |
4 ms |
6560 KB |
Output is correct |
43 |
Correct |
2 ms |
5208 KB |
Output is correct |
44 |
Correct |
2 ms |
5464 KB |
Output is correct |
45 |
Correct |
1 ms |
5212 KB |
Output is correct |
46 |
Correct |
1 ms |
5208 KB |
Output is correct |
47 |
Correct |
1 ms |
5212 KB |
Output is correct |
48 |
Correct |
1 ms |
5212 KB |
Output is correct |
49 |
Correct |
1 ms |
5212 KB |
Output is correct |
50 |
Correct |
2 ms |
5212 KB |
Output is correct |
51 |
Correct |
1 ms |
5212 KB |
Output is correct |
52 |
Correct |
1 ms |
5212 KB |
Output is correct |
53 |
Correct |
1 ms |
5212 KB |
Output is correct |
54 |
Correct |
1 ms |
5212 KB |
Output is correct |
55 |
Correct |
1 ms |
5208 KB |
Output is correct |
56 |
Correct |
1 ms |
5444 KB |
Output is correct |
57 |
Correct |
29 ms |
10832 KB |
Output is correct |
58 |
Correct |
30 ms |
10836 KB |
Output is correct |
59 |
Correct |
28 ms |
10836 KB |
Output is correct |
60 |
Correct |
30 ms |
10836 KB |
Output is correct |
61 |
Correct |
28 ms |
10832 KB |
Output is correct |
62 |
Correct |
27 ms |
10836 KB |
Output is correct |
63 |
Correct |
26 ms |
10576 KB |
Output is correct |
64 |
Correct |
30 ms |
10580 KB |
Output is correct |
65 |
Correct |
27 ms |
10844 KB |
Output is correct |
66 |
Correct |
30 ms |
10716 KB |
Output is correct |
67 |
Correct |
29 ms |
10836 KB |
Output is correct |
68 |
Correct |
29 ms |
10832 KB |
Output is correct |
69 |
Correct |
36 ms |
10968 KB |
Output is correct |
70 |
Correct |
29 ms |
11088 KB |
Output is correct |
71 |
Correct |
1 ms |
5212 KB |
Output is correct |
72 |
Correct |
2 ms |
5488 KB |
Output is correct |
73 |
Correct |
1 ms |
5484 KB |
Output is correct |
74 |
Correct |
2 ms |
5468 KB |
Output is correct |
75 |
Correct |
2 ms |
5468 KB |
Output is correct |
76 |
Correct |
2 ms |
5468 KB |
Output is correct |
77 |
Correct |
2 ms |
5468 KB |
Output is correct |
78 |
Correct |
1 ms |
5620 KB |
Output is correct |
79 |
Correct |
1 ms |
5468 KB |
Output is correct |
80 |
Correct |
31 ms |
10844 KB |
Output is correct |
81 |
Correct |
31 ms |
10860 KB |
Output is correct |
82 |
Correct |
29 ms |
10836 KB |
Output is correct |
83 |
Correct |
33 ms |
11004 KB |
Output is correct |
84 |
Correct |
1 ms |
5468 KB |
Output is correct |
85 |
Correct |
1 ms |
5468 KB |
Output is correct |
86 |
Correct |
1 ms |
5456 KB |
Output is correct |
87 |
Correct |
1 ms |
5468 KB |
Output is correct |
88 |
Correct |
1 ms |
5508 KB |
Output is correct |
89 |
Correct |
2 ms |
5468 KB |
Output is correct |
90 |
Correct |
1 ms |
5468 KB |
Output is correct |
91 |
Correct |
2 ms |
5468 KB |
Output is correct |
92 |
Correct |
2 ms |
5468 KB |
Output is correct |
93 |
Correct |
1 ms |
5468 KB |
Output is correct |
94 |
Correct |
1 ms |
5212 KB |
Output is correct |
95 |
Correct |
1 ms |
5212 KB |
Output is correct |
96 |
Correct |
1 ms |
5212 KB |
Output is correct |
97 |
Correct |
1 ms |
5440 KB |
Output is correct |
98 |
Correct |
1 ms |
5440 KB |
Output is correct |
99 |
Correct |
1 ms |
5212 KB |
Output is correct |
100 |
Correct |
1 ms |
5212 KB |
Output is correct |
101 |
Correct |
1 ms |
5212 KB |
Output is correct |
102 |
Correct |
1 ms |
5212 KB |
Output is correct |
103 |
Correct |
1 ms |
5212 KB |
Output is correct |
104 |
Correct |
3 ms |
5980 KB |
Output is correct |
105 |
Correct |
7 ms |
7260 KB |
Output is correct |
106 |
Correct |
1 ms |
5468 KB |
Output is correct |
107 |
Correct |
12 ms |
8900 KB |
Output is correct |
108 |
Correct |
16 ms |
10860 KB |
Output is correct |
109 |
Correct |
1 ms |
5468 KB |
Output is correct |
110 |
Correct |
22 ms |
11356 KB |
Output is correct |
111 |
Correct |
27 ms |
12468 KB |
Output is correct |
112 |
Correct |
1 ms |
5468 KB |
Output is correct |
113 |
Correct |
37 ms |
18044 KB |
Output is correct |
114 |
Correct |
11 ms |
7516 KB |
Output is correct |
115 |
Incorrect |
9 ms |
7516 KB |
Output isn't correct |
116 |
Halted |
0 ms |
0 KB |
- |