Submission #843710

# Submission time Handle Problem Language Result Execution time Memory
843710 2023-09-04T13:00:14 Z nonono Dreaming (IOI13_dreaming) C++17
47 / 100
71 ms 36304 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;

const int mxN = 100005;

vector<vector<pair<int, int>>> adj(mxN);
int mark[mxN];
int high[mxN], _high[mxN];
vector<int> vertex;

void dfs(int u, int par) {
    vertex.push_back(u);
    mark[u] = 1;
    high[u] = 0;
    
    for(auto [v, w] : adj[u]) {
        if(v == par) continue ;
        dfs(v, u);
        high[u] = max(high[u], high[v] + w);
    }
}

void reroot(int u, int par) {
    vector<pair<int, int>> k;
    vector<int> L, R;
    
    for(auto [v, w] : adj[u]) {
        if(v == par) continue ;
        k.push_back({v, w});
    }
   
   for(int i = 0; i < k.size(); i ++) {
       auto [v, w] = k[i];
       L.push_back(max((!L.empty() ? L.back() : 0), high[v] + w));
   }
   
   for(int i = 0; i < k.size(); i ++) {
       auto [v, w] = k[k.size() - 1 - i];
       R.push_back(max((!R.empty() ? R.back() : 0), high[v] + w));
   }
   
   reverse(R.begin(), R.end());
   
   for(int i = 0; i < k.size(); i ++) {
       auto [v, w] = k[i];
       if(v == par) continue ;
       
       _high[v] = max(_high[v], _high[u] + w);
       if(i) _high[v] = max(_high[v], L[i - 1] + w);
       if(i + 1 < R.size()) _high[v] = max(_high[v], R[i + 1] + w);
       reroot(v, u);
   }
}

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]});
    }
    
    vector<int> f;
    int ans = 0;
    
    for(int i = 0; i < N; i ++) {
        if(!mark[i]) {
            dfs(i, i);
            reroot(i, i);
            
            int timer = max(high[vertex.back()], _high[vertex.back()]);
            for(int x : vertex) {
                ans = max(ans, high[x] + _high[x]);
                timer = min(timer, max(high[x], _high[x]));
            }
            
            f.push_back(timer);
            vertex.clear();
        }
    }
    
    sort(f.begin(), f.end());
    
    if(f.size() > 1) {
        ans = max(ans, f.back() + f[f.size() - 2] + L);
    }
    
    return ans;
}

Compilation message

dreaming.cpp: In function 'void reroot(int, int)':
dreaming.cpp:33:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |    for(int i = 0; i < k.size(); i ++) {
      |                   ~~^~~~~~~~~~
dreaming.cpp:38:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |    for(int i = 0; i < k.size(); i ++) {
      |                   ~~^~~~~~~~~~
dreaming.cpp:45:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |    for(int i = 0; i < k.size(); i ++) {
      |                   ~~^~~~~~~~~~
dreaming.cpp:51:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |        if(i + 1 < R.size()) _high[v] = max(_high[v], R[i + 1] + w);
      |           ~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 54 ms 22484 KB Output is correct
2 Correct 47 ms 21452 KB Output is correct
3 Correct 38 ms 21536 KB Output is correct
4 Correct 7 ms 7260 KB Output is correct
5 Correct 6 ms 5980 KB Output is correct
6 Correct 12 ms 8540 KB Output is correct
7 Correct 2 ms 4700 KB Output is correct
8 Correct 24 ms 11660 KB Output is correct
9 Correct 32 ms 17628 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 41 ms 16476 KB Output is correct
12 Correct 60 ms 19476 KB Output is correct
13 Correct 2 ms 4952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4712 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 2 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 2 ms 4696 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 2 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 2 ms 4756 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4696 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 2 ms 4700 KB Output is correct
18 Correct 1 ms 4864 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 1 ms 4700 KB Output is correct
22 Correct 2 ms 4696 KB Output is correct
23 Correct 1 ms 4700 KB Output is correct
24 Correct 1 ms 4700 KB Output is correct
25 Correct 1 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 22484 KB Output is correct
2 Correct 47 ms 21452 KB Output is correct
3 Correct 38 ms 21536 KB Output is correct
4 Correct 7 ms 7260 KB Output is correct
5 Correct 6 ms 5980 KB Output is correct
6 Correct 12 ms 8540 KB Output is correct
7 Correct 2 ms 4700 KB Output is correct
8 Correct 24 ms 11660 KB Output is correct
9 Correct 32 ms 17628 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 41 ms 16476 KB Output is correct
12 Correct 60 ms 19476 KB Output is correct
13 Correct 2 ms 4952 KB Output is correct
14 Correct 2 ms 4712 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 2 ms 4700 KB Output is correct
18 Correct 1 ms 4700 KB Output is correct
19 Correct 2 ms 4696 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 1 ms 4700 KB Output is correct
22 Correct 2 ms 4700 KB Output is correct
23 Correct 1 ms 4700 KB Output is correct
24 Correct 1 ms 4700 KB Output is correct
25 Correct 2 ms 4756 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 1 ms 4696 KB Output is correct
28 Correct 1 ms 4700 KB Output is correct
29 Correct 1 ms 4700 KB Output is correct
30 Correct 2 ms 4700 KB Output is correct
31 Correct 1 ms 4864 KB Output is correct
32 Correct 1 ms 4700 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 1 ms 4700 KB Output is correct
35 Correct 2 ms 4696 KB Output is correct
36 Correct 1 ms 4700 KB Output is correct
37 Correct 1 ms 4700 KB Output is correct
38 Correct 1 ms 4700 KB Output is correct
39 Correct 53 ms 22492 KB Output is correct
40 Correct 56 ms 21412 KB Output is correct
41 Correct 33 ms 21460 KB Output is correct
42 Correct 7 ms 7260 KB Output is correct
43 Correct 2 ms 4696 KB Output is correct
44 Correct 1 ms 4696 KB Output is correct
45 Correct 1 ms 4700 KB Output is correct
46 Correct 1 ms 4696 KB Output is correct
47 Correct 1 ms 4700 KB Output is correct
48 Correct 2 ms 4700 KB Output is correct
49 Correct 1 ms 4700 KB Output is correct
50 Correct 1 ms 4652 KB Output is correct
51 Correct 2 ms 4700 KB Output is correct
52 Correct 2 ms 4700 KB Output is correct
53 Correct 1 ms 4700 KB Output is correct
54 Correct 1 ms 4700 KB Output is correct
55 Correct 1 ms 4700 KB Output is correct
56 Correct 1 ms 4700 KB Output is correct
57 Correct 54 ms 9680 KB Output is correct
58 Correct 47 ms 9432 KB Output is correct
59 Correct 44 ms 9692 KB Output is correct
60 Correct 45 ms 9424 KB Output is correct
61 Correct 44 ms 9436 KB Output is correct
62 Correct 43 ms 9264 KB Output is correct
63 Correct 44 ms 9264 KB Output is correct
64 Correct 45 ms 9344 KB Output is correct
65 Correct 44 ms 9432 KB Output is correct
66 Correct 45 ms 9428 KB Output is correct
67 Correct 45 ms 9692 KB Output is correct
68 Correct 50 ms 9596 KB Output is correct
69 Correct 50 ms 9388 KB Output is correct
70 Correct 46 ms 9392 KB Output is correct
71 Correct 1 ms 4696 KB Output is correct
72 Correct 2 ms 4952 KB Output is correct
73 Correct 2 ms 4956 KB Output is correct
74 Correct 3 ms 4956 KB Output is correct
75 Correct 3 ms 4852 KB Output is correct
76 Correct 2 ms 4956 KB Output is correct
77 Correct 3 ms 4956 KB Output is correct
78 Correct 3 ms 4956 KB Output is correct
79 Correct 3 ms 4956 KB Output is correct
80 Correct 45 ms 9548 KB Output is correct
81 Correct 45 ms 9648 KB Output is correct
82 Correct 45 ms 9428 KB Output is correct
83 Correct 44 ms 9440 KB Output is correct
84 Correct 2 ms 4956 KB Output is correct
85 Correct 2 ms 4956 KB Output is correct
86 Correct 2 ms 4956 KB Output is correct
87 Correct 2 ms 4956 KB Output is correct
88 Correct 2 ms 4956 KB Output is correct
89 Correct 2 ms 4848 KB Output is correct
90 Correct 2 ms 4956 KB Output is correct
91 Correct 2 ms 4956 KB Output is correct
92 Correct 2 ms 4956 KB Output is correct
93 Correct 2 ms 4956 KB Output is correct
94 Correct 1 ms 4700 KB Output is correct
95 Correct 2 ms 4700 KB Output is correct
96 Correct 1 ms 4700 KB Output is correct
97 Correct 2 ms 4700 KB Output is correct
98 Correct 1 ms 4700 KB Output is correct
99 Correct 1 ms 4700 KB Output is correct
100 Correct 1 ms 4700 KB Output is correct
101 Correct 1 ms 4696 KB Output is correct
102 Correct 1 ms 4700 KB Output is correct
103 Correct 1 ms 4700 KB Output is correct
104 Correct 6 ms 5980 KB Output is correct
105 Correct 11 ms 8540 KB Output is correct
106 Correct 2 ms 4700 KB Output is correct
107 Correct 24 ms 11684 KB Output is correct
108 Correct 31 ms 17628 KB Output is correct
109 Correct 2 ms 4956 KB Output is correct
110 Correct 41 ms 16604 KB Output is correct
111 Correct 45 ms 19408 KB Output is correct
112 Correct 2 ms 4956 KB Output is correct
113 Correct 71 ms 36304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 7316 KB Output is correct
2 Incorrect 16 ms 7388 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4712 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 2 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 2 ms 4696 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 2 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 2 ms 4756 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4696 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 2 ms 4700 KB Output is correct
18 Correct 1 ms 4864 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 1 ms 4700 KB Output is correct
22 Correct 2 ms 4696 KB Output is correct
23 Correct 1 ms 4700 KB Output is correct
24 Correct 1 ms 4700 KB Output is correct
25 Correct 1 ms 4700 KB Output is correct
26 Correct 2 ms 4700 KB Output is correct
27 Correct 2 ms 4696 KB Output is correct
28 Correct 3 ms 4956 KB Output is correct
29 Correct 2 ms 4700 KB Output is correct
30 Correct 2 ms 4700 KB Output is correct
31 Correct 2 ms 4956 KB Output is correct
32 Incorrect 2 ms 4700 KB Output isn't correct
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 54 ms 22484 KB Output is correct
2 Correct 47 ms 21452 KB Output is correct
3 Correct 38 ms 21536 KB Output is correct
4 Correct 7 ms 7260 KB Output is correct
5 Correct 6 ms 5980 KB Output is correct
6 Correct 12 ms 8540 KB Output is correct
7 Correct 2 ms 4700 KB Output is correct
8 Correct 24 ms 11660 KB Output is correct
9 Correct 32 ms 17628 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 41 ms 16476 KB Output is correct
12 Correct 60 ms 19476 KB Output is correct
13 Correct 2 ms 4952 KB Output is correct
14 Correct 2 ms 4712 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 2 ms 4700 KB Output is correct
18 Correct 1 ms 4700 KB Output is correct
19 Correct 2 ms 4696 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 1 ms 4700 KB Output is correct
22 Correct 2 ms 4700 KB Output is correct
23 Correct 1 ms 4700 KB Output is correct
24 Correct 1 ms 4700 KB Output is correct
25 Correct 2 ms 4756 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 1 ms 4696 KB Output is correct
28 Correct 1 ms 4700 KB Output is correct
29 Correct 1 ms 4700 KB Output is correct
30 Correct 2 ms 4700 KB Output is correct
31 Correct 1 ms 4864 KB Output is correct
32 Correct 1 ms 4700 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 1 ms 4700 KB Output is correct
35 Correct 2 ms 4696 KB Output is correct
36 Correct 1 ms 4700 KB Output is correct
37 Correct 1 ms 4700 KB Output is correct
38 Correct 1 ms 4700 KB Output is correct
39 Correct 53 ms 22492 KB Output is correct
40 Correct 56 ms 21412 KB Output is correct
41 Correct 33 ms 21460 KB Output is correct
42 Correct 7 ms 7260 KB Output is correct
43 Correct 2 ms 4696 KB Output is correct
44 Correct 1 ms 4696 KB Output is correct
45 Correct 1 ms 4700 KB Output is correct
46 Correct 1 ms 4696 KB Output is correct
47 Correct 1 ms 4700 KB Output is correct
48 Correct 2 ms 4700 KB Output is correct
49 Correct 1 ms 4700 KB Output is correct
50 Correct 1 ms 4652 KB Output is correct
51 Correct 2 ms 4700 KB Output is correct
52 Correct 2 ms 4700 KB Output is correct
53 Correct 1 ms 4700 KB Output is correct
54 Correct 1 ms 4700 KB Output is correct
55 Correct 1 ms 4700 KB Output is correct
56 Correct 1 ms 4700 KB Output is correct
57 Correct 54 ms 9680 KB Output is correct
58 Correct 47 ms 9432 KB Output is correct
59 Correct 44 ms 9692 KB Output is correct
60 Correct 45 ms 9424 KB Output is correct
61 Correct 44 ms 9436 KB Output is correct
62 Correct 43 ms 9264 KB Output is correct
63 Correct 44 ms 9264 KB Output is correct
64 Correct 45 ms 9344 KB Output is correct
65 Correct 44 ms 9432 KB Output is correct
66 Correct 45 ms 9428 KB Output is correct
67 Correct 45 ms 9692 KB Output is correct
68 Correct 50 ms 9596 KB Output is correct
69 Correct 50 ms 9388 KB Output is correct
70 Correct 46 ms 9392 KB Output is correct
71 Correct 1 ms 4696 KB Output is correct
72 Correct 2 ms 4952 KB Output is correct
73 Correct 2 ms 4956 KB Output is correct
74 Correct 3 ms 4956 KB Output is correct
75 Correct 3 ms 4852 KB Output is correct
76 Correct 2 ms 4956 KB Output is correct
77 Correct 3 ms 4956 KB Output is correct
78 Correct 3 ms 4956 KB Output is correct
79 Correct 3 ms 4956 KB Output is correct
80 Correct 45 ms 9548 KB Output is correct
81 Correct 45 ms 9648 KB Output is correct
82 Correct 45 ms 9428 KB Output is correct
83 Correct 44 ms 9440 KB Output is correct
84 Correct 2 ms 4956 KB Output is correct
85 Correct 2 ms 4956 KB Output is correct
86 Correct 2 ms 4956 KB Output is correct
87 Correct 2 ms 4956 KB Output is correct
88 Correct 2 ms 4956 KB Output is correct
89 Correct 2 ms 4848 KB Output is correct
90 Correct 2 ms 4956 KB Output is correct
91 Correct 2 ms 4956 KB Output is correct
92 Correct 2 ms 4956 KB Output is correct
93 Correct 2 ms 4956 KB Output is correct
94 Correct 1 ms 4700 KB Output is correct
95 Correct 2 ms 4700 KB Output is correct
96 Correct 1 ms 4700 KB Output is correct
97 Correct 2 ms 4700 KB Output is correct
98 Correct 1 ms 4700 KB Output is correct
99 Correct 1 ms 4700 KB Output is correct
100 Correct 1 ms 4700 KB Output is correct
101 Correct 1 ms 4696 KB Output is correct
102 Correct 1 ms 4700 KB Output is correct
103 Correct 1 ms 4700 KB Output is correct
104 Correct 6 ms 5980 KB Output is correct
105 Correct 11 ms 8540 KB Output is correct
106 Correct 2 ms 4700 KB Output is correct
107 Correct 24 ms 11684 KB Output is correct
108 Correct 31 ms 17628 KB Output is correct
109 Correct 2 ms 4956 KB Output is correct
110 Correct 41 ms 16604 KB Output is correct
111 Correct 45 ms 19408 KB Output is correct
112 Correct 2 ms 4956 KB Output is correct
113 Correct 71 ms 36304 KB Output is correct
114 Correct 18 ms 7316 KB Output is correct
115 Incorrect 16 ms 7388 KB Output isn't correct
116 Halted 0 ms 0 KB -