# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1043786 |
2024-08-04T17:31:57 Z |
vanea |
Dreaming (IOI13_dreaming) |
C++14 |
|
36 ms |
16304 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 {
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]);
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 |
21 ms |
12380 KB |
Output is correct |
2 |
Correct |
23 ms |
12128 KB |
Output is correct |
3 |
Correct |
15 ms |
11356 KB |
Output is correct |
4 |
Correct |
4 ms |
6232 KB |
Output is correct |
5 |
Correct |
4 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 |
12 ms |
8380 KB |
Output is correct |
9 |
Correct |
18 ms |
10076 KB |
Output is correct |
10 |
Correct |
1 ms |
5468 KB |
Output is correct |
11 |
Correct |
26 ms |
10344 KB |
Output is correct |
12 |
Correct |
35 ms |
11352 KB |
Output is correct |
13 |
Correct |
1 ms |
5468 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 |
5212 KB |
Output is correct |
4 |
Correct |
1 ms |
5212 KB |
Output is correct |
5 |
Correct |
1 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 |
5212 KB |
Output is correct |
11 |
Correct |
1 ms |
5464 KB |
Output is correct |
12 |
Correct |
1 ms |
5212 KB |
Output is correct |
13 |
Correct |
1 ms |
5212 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 |
5212 KB |
Output is correct |
17 |
Correct |
1 ms |
5212 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 |
5212 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 |
21 ms |
12380 KB |
Output is correct |
2 |
Correct |
23 ms |
12128 KB |
Output is correct |
3 |
Correct |
15 ms |
11356 KB |
Output is correct |
4 |
Correct |
4 ms |
6232 KB |
Output is correct |
5 |
Correct |
4 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 |
12 ms |
8380 KB |
Output is correct |
9 |
Correct |
18 ms |
10076 KB |
Output is correct |
10 |
Correct |
1 ms |
5468 KB |
Output is correct |
11 |
Correct |
26 ms |
10344 KB |
Output is correct |
12 |
Correct |
35 ms |
11352 KB |
Output is correct |
13 |
Correct |
1 ms |
5468 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 |
5212 KB |
Output is correct |
17 |
Correct |
1 ms |
5212 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 |
5212 KB |
Output is correct |
23 |
Correct |
1 ms |
5212 KB |
Output is correct |
24 |
Correct |
1 ms |
5464 KB |
Output is correct |
25 |
Correct |
1 ms |
5212 KB |
Output is correct |
26 |
Correct |
1 ms |
5212 KB |
Output is correct |
27 |
Correct |
1 ms |
5212 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 |
5212 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 |
5212 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 |
25 ms |
12380 KB |
Output is correct |
40 |
Correct |
23 ms |
11868 KB |
Output is correct |
41 |
Correct |
16 ms |
11356 KB |
Output is correct |
42 |
Correct |
4 ms |
6236 KB |
Output is correct |
43 |
Correct |
1 ms |
5296 KB |
Output is correct |
44 |
Correct |
1 ms |
5212 KB |
Output is correct |
45 |
Correct |
1 ms |
5212 KB |
Output is correct |
46 |
Correct |
1 ms |
5212 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 |
1 ms |
5208 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 |
5212 KB |
Output is correct |
56 |
Correct |
1 ms |
5212 KB |
Output is correct |
57 |
Correct |
27 ms |
9620 KB |
Output is correct |
58 |
Correct |
33 ms |
9552 KB |
Output is correct |
59 |
Correct |
31 ms |
9560 KB |
Output is correct |
60 |
Correct |
28 ms |
9308 KB |
Output is correct |
61 |
Correct |
29 ms |
9308 KB |
Output is correct |
62 |
Correct |
28 ms |
9360 KB |
Output is correct |
63 |
Correct |
29 ms |
9052 KB |
Output is correct |
64 |
Correct |
27 ms |
9040 KB |
Output is correct |
65 |
Correct |
30 ms |
9240 KB |
Output is correct |
66 |
Correct |
26 ms |
9052 KB |
Output is correct |
67 |
Correct |
27 ms |
9364 KB |
Output is correct |
68 |
Correct |
32 ms |
9524 KB |
Output is correct |
69 |
Correct |
35 ms |
9308 KB |
Output is correct |
70 |
Correct |
33 ms |
9452 KB |
Output is correct |
71 |
Correct |
1 ms |
5208 KB |
Output is correct |
72 |
Correct |
1 ms |
5464 KB |
Output is correct |
73 |
Correct |
2 ms |
5464 KB |
Output is correct |
74 |
Correct |
1 ms |
5464 KB |
Output is correct |
75 |
Correct |
1 ms |
5464 KB |
Output is correct |
76 |
Correct |
2 ms |
5468 KB |
Output is correct |
77 |
Correct |
1 ms |
5468 KB |
Output is correct |
78 |
Correct |
1 ms |
5468 KB |
Output is correct |
79 |
Correct |
2 ms |
5468 KB |
Output is correct |
80 |
Correct |
27 ms |
9308 KB |
Output is correct |
81 |
Correct |
32 ms |
9300 KB |
Output is correct |
82 |
Correct |
26 ms |
9304 KB |
Output is correct |
83 |
Correct |
29 ms |
9308 KB |
Output is correct |
84 |
Correct |
1 ms |
5464 KB |
Output is correct |
85 |
Correct |
1 ms |
5468 KB |
Output is correct |
86 |
Correct |
2 ms |
5468 KB |
Output is correct |
87 |
Correct |
2 ms |
5468 KB |
Output is correct |
88 |
Correct |
2 ms |
5468 KB |
Output is correct |
89 |
Correct |
1 ms |
5468 KB |
Output is correct |
90 |
Correct |
1 ms |
5468 KB |
Output is correct |
91 |
Correct |
1 ms |
5468 KB |
Output is correct |
92 |
Correct |
1 ms |
5536 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 |
5212 KB |
Output is correct |
98 |
Correct |
1 ms |
5464 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 |
6012 KB |
Output is correct |
105 |
Correct |
7 ms |
7004 KB |
Output is correct |
106 |
Correct |
1 ms |
5212 KB |
Output is correct |
107 |
Correct |
12 ms |
8332 KB |
Output is correct |
108 |
Correct |
17 ms |
10076 KB |
Output is correct |
109 |
Correct |
1 ms |
5468 KB |
Output is correct |
110 |
Correct |
25 ms |
10412 KB |
Output is correct |
111 |
Correct |
25 ms |
11368 KB |
Output is correct |
112 |
Correct |
2 ms |
5468 KB |
Output is correct |
113 |
Correct |
36 ms |
16304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 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 |
5212 KB |
Output is correct |
4 |
Correct |
1 ms |
5212 KB |
Output is correct |
5 |
Correct |
1 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 |
5212 KB |
Output is correct |
11 |
Correct |
1 ms |
5464 KB |
Output is correct |
12 |
Correct |
1 ms |
5212 KB |
Output is correct |
13 |
Correct |
1 ms |
5212 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 |
5212 KB |
Output is correct |
17 |
Correct |
1 ms |
5212 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 |
5212 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 |
5468 KB |
Output is correct |
27 |
Correct |
1 ms |
5468 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 |
5468 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
12380 KB |
Output is correct |
2 |
Correct |
23 ms |
12128 KB |
Output is correct |
3 |
Correct |
15 ms |
11356 KB |
Output is correct |
4 |
Correct |
4 ms |
6232 KB |
Output is correct |
5 |
Correct |
4 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 |
12 ms |
8380 KB |
Output is correct |
9 |
Correct |
18 ms |
10076 KB |
Output is correct |
10 |
Correct |
1 ms |
5468 KB |
Output is correct |
11 |
Correct |
26 ms |
10344 KB |
Output is correct |
12 |
Correct |
35 ms |
11352 KB |
Output is correct |
13 |
Correct |
1 ms |
5468 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 |
5212 KB |
Output is correct |
17 |
Correct |
1 ms |
5212 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 |
5212 KB |
Output is correct |
23 |
Correct |
1 ms |
5212 KB |
Output is correct |
24 |
Correct |
1 ms |
5464 KB |
Output is correct |
25 |
Correct |
1 ms |
5212 KB |
Output is correct |
26 |
Correct |
1 ms |
5212 KB |
Output is correct |
27 |
Correct |
1 ms |
5212 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 |
5212 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 |
5212 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 |
25 ms |
12380 KB |
Output is correct |
40 |
Correct |
23 ms |
11868 KB |
Output is correct |
41 |
Correct |
16 ms |
11356 KB |
Output is correct |
42 |
Correct |
4 ms |
6236 KB |
Output is correct |
43 |
Correct |
1 ms |
5296 KB |
Output is correct |
44 |
Correct |
1 ms |
5212 KB |
Output is correct |
45 |
Correct |
1 ms |
5212 KB |
Output is correct |
46 |
Correct |
1 ms |
5212 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 |
1 ms |
5208 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 |
5212 KB |
Output is correct |
56 |
Correct |
1 ms |
5212 KB |
Output is correct |
57 |
Correct |
27 ms |
9620 KB |
Output is correct |
58 |
Correct |
33 ms |
9552 KB |
Output is correct |
59 |
Correct |
31 ms |
9560 KB |
Output is correct |
60 |
Correct |
28 ms |
9308 KB |
Output is correct |
61 |
Correct |
29 ms |
9308 KB |
Output is correct |
62 |
Correct |
28 ms |
9360 KB |
Output is correct |
63 |
Correct |
29 ms |
9052 KB |
Output is correct |
64 |
Correct |
27 ms |
9040 KB |
Output is correct |
65 |
Correct |
30 ms |
9240 KB |
Output is correct |
66 |
Correct |
26 ms |
9052 KB |
Output is correct |
67 |
Correct |
27 ms |
9364 KB |
Output is correct |
68 |
Correct |
32 ms |
9524 KB |
Output is correct |
69 |
Correct |
35 ms |
9308 KB |
Output is correct |
70 |
Correct |
33 ms |
9452 KB |
Output is correct |
71 |
Correct |
1 ms |
5208 KB |
Output is correct |
72 |
Correct |
1 ms |
5464 KB |
Output is correct |
73 |
Correct |
2 ms |
5464 KB |
Output is correct |
74 |
Correct |
1 ms |
5464 KB |
Output is correct |
75 |
Correct |
1 ms |
5464 KB |
Output is correct |
76 |
Correct |
2 ms |
5468 KB |
Output is correct |
77 |
Correct |
1 ms |
5468 KB |
Output is correct |
78 |
Correct |
1 ms |
5468 KB |
Output is correct |
79 |
Correct |
2 ms |
5468 KB |
Output is correct |
80 |
Correct |
27 ms |
9308 KB |
Output is correct |
81 |
Correct |
32 ms |
9300 KB |
Output is correct |
82 |
Correct |
26 ms |
9304 KB |
Output is correct |
83 |
Correct |
29 ms |
9308 KB |
Output is correct |
84 |
Correct |
1 ms |
5464 KB |
Output is correct |
85 |
Correct |
1 ms |
5468 KB |
Output is correct |
86 |
Correct |
2 ms |
5468 KB |
Output is correct |
87 |
Correct |
2 ms |
5468 KB |
Output is correct |
88 |
Correct |
2 ms |
5468 KB |
Output is correct |
89 |
Correct |
1 ms |
5468 KB |
Output is correct |
90 |
Correct |
1 ms |
5468 KB |
Output is correct |
91 |
Correct |
1 ms |
5468 KB |
Output is correct |
92 |
Correct |
1 ms |
5536 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 |
5212 KB |
Output is correct |
98 |
Correct |
1 ms |
5464 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 |
6012 KB |
Output is correct |
105 |
Correct |
7 ms |
7004 KB |
Output is correct |
106 |
Correct |
1 ms |
5212 KB |
Output is correct |
107 |
Correct |
12 ms |
8332 KB |
Output is correct |
108 |
Correct |
17 ms |
10076 KB |
Output is correct |
109 |
Correct |
1 ms |
5468 KB |
Output is correct |
110 |
Correct |
25 ms |
10412 KB |
Output is correct |
111 |
Correct |
25 ms |
11368 KB |
Output is correct |
112 |
Correct |
2 ms |
5468 KB |
Output is correct |
113 |
Correct |
36 ms |
16304 KB |
Output is correct |
114 |
Correct |
12 ms |
7516 KB |
Output is correct |
115 |
Incorrect |
9 ms |
7516 KB |
Output isn't correct |
116 |
Halted |
0 ms |
0 KB |
- |