Submission #797797

# Submission time Handle Problem Language Result Execution time Memory
797797 2023-07-29T23:23:58 Z gg123_pe Dreaming (IOI13_dreaming) C++14
47 / 100
52 ms 17996 KB
#include "dreaming.h"
#include <bits/stdc++.h> 
using namespace std; 

#define f(i,a,b) for(int i = a; i < b; i++)
const int N = 1e5 + 5; 

int n; 
int d[N], p[N], W[N]; 
vector <pair<int,int>> adj[N]; 
vector <int> used; 

void dfs(int u, int f){
    used.push_back(u);  
    for(auto pa: adj[u]){
        int v = pa.first, w = pa.second; 
        if(v == f) continue;
        d[v] = d[u] + w; 
        p[v] = u, W[v] = w; 
        dfs(v, u); 
    }
}
pair<int,int> get(int u){
    d[u] = 0, p[u] = -1, W[u] = 0; 
    used.clear(); 
    dfs(u, -1); 
    int node = -1, maxi = -1; 
    for(int u: used){
        if(d[u] > maxi){
            maxi = d[u], node = u; 
        }
    }
    return {node, maxi}; 
}
int travelTime(int Ni, int M, int L, int A[], int B[], int T[]) {
    n = Ni; 

    f(i,0,M){
        adj[A[i]].push_back({B[i], T[i]});  
        adj[B[i]].push_back({A[i], T[i]}); 
    }

    memset(d, -1, sizeof d); 

    int ans = 0; 
    int x = -1, y = -1, z = -1; 

    f(i,0,n){
        if(d[i] != -1) continue; 
        auto ra = get(i); 
        auto ta = get(ra.first);
        int leaf = ta.first, dim = ta.second; 
        int curr = 0, mini = dim; 
        
        ans = max(ans, dim); 

        while(leaf != ra.first){
            curr += W[leaf]; 
            mini = min(mini, max(curr, abs(dim - curr))); 
            leaf = p[leaf]; 
        }
        if(mini > x) z = y, y = x, x = mini; 
        else if(mini > y) z = y, y = mini; 
        else if(mini > z) z = mini; 
    }
    ans = max(ans, x + y + L); 
    if(z != -1) ans = max(ans, y + z + 2*L); 

    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 35 ms 15220 KB Output is correct
2 Correct 34 ms 16456 KB Output is correct
3 Correct 24 ms 12088 KB Output is correct
4 Correct 6 ms 5076 KB Output is correct
5 Correct 5 ms 4092 KB Output is correct
6 Correct 10 ms 6108 KB Output is correct
7 Correct 2 ms 3028 KB Output is correct
8 Correct 17 ms 7724 KB Output is correct
9 Correct 21 ms 9708 KB Output is correct
10 Correct 2 ms 3028 KB Output is correct
11 Correct 31 ms 11792 KB Output is correct
12 Correct 35 ms 13932 KB Output is correct
13 Correct 2 ms 3156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3028 KB Output is correct
2 Correct 2 ms 3048 KB Output is correct
3 Correct 1 ms 3028 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 2 ms 3028 KB Output is correct
6 Correct 1 ms 3028 KB Output is correct
7 Correct 2 ms 3028 KB Output is correct
8 Correct 2 ms 3028 KB Output is correct
9 Correct 1 ms 3028 KB Output is correct
10 Correct 2 ms 3028 KB Output is correct
11 Correct 2 ms 3028 KB Output is correct
12 Correct 1 ms 3048 KB Output is correct
13 Correct 1 ms 3028 KB Output is correct
14 Correct 2 ms 3028 KB Output is correct
15 Correct 2 ms 3028 KB Output is correct
16 Correct 2 ms 3028 KB Output is correct
17 Correct 2 ms 3080 KB Output is correct
18 Correct 2 ms 3052 KB Output is correct
19 Correct 2 ms 3044 KB Output is correct
20 Correct 2 ms 3028 KB Output is correct
21 Correct 2 ms 3028 KB Output is correct
22 Correct 1 ms 3028 KB Output is correct
23 Correct 2 ms 3028 KB Output is correct
24 Correct 2 ms 3048 KB Output is correct
25 Correct 1 ms 3028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 15220 KB Output is correct
2 Correct 34 ms 16456 KB Output is correct
3 Correct 24 ms 12088 KB Output is correct
4 Correct 6 ms 5076 KB Output is correct
5 Correct 5 ms 4092 KB Output is correct
6 Correct 10 ms 6108 KB Output is correct
7 Correct 2 ms 3028 KB Output is correct
8 Correct 17 ms 7724 KB Output is correct
9 Correct 21 ms 9708 KB Output is correct
10 Correct 2 ms 3028 KB Output is correct
11 Correct 31 ms 11792 KB Output is correct
12 Correct 35 ms 13932 KB Output is correct
13 Correct 2 ms 3156 KB Output is correct
14 Correct 1 ms 3028 KB Output is correct
15 Correct 2 ms 3048 KB Output is correct
16 Correct 1 ms 3028 KB Output is correct
17 Correct 2 ms 3028 KB Output is correct
18 Correct 2 ms 3028 KB Output is correct
19 Correct 1 ms 3028 KB Output is correct
20 Correct 2 ms 3028 KB Output is correct
21 Correct 2 ms 3028 KB Output is correct
22 Correct 1 ms 3028 KB Output is correct
23 Correct 2 ms 3028 KB Output is correct
24 Correct 2 ms 3028 KB Output is correct
25 Correct 1 ms 3048 KB Output is correct
26 Correct 1 ms 3028 KB Output is correct
27 Correct 2 ms 3028 KB Output is correct
28 Correct 2 ms 3028 KB Output is correct
29 Correct 2 ms 3028 KB Output is correct
30 Correct 2 ms 3080 KB Output is correct
31 Correct 2 ms 3052 KB Output is correct
32 Correct 2 ms 3044 KB Output is correct
33 Correct 2 ms 3028 KB Output is correct
34 Correct 2 ms 3028 KB Output is correct
35 Correct 1 ms 3028 KB Output is correct
36 Correct 2 ms 3028 KB Output is correct
37 Correct 2 ms 3048 KB Output is correct
38 Correct 1 ms 3028 KB Output is correct
39 Correct 37 ms 16512 KB Output is correct
40 Correct 35 ms 16472 KB Output is correct
41 Correct 23 ms 12012 KB Output is correct
42 Correct 6 ms 5076 KB Output is correct
43 Correct 1 ms 3028 KB Output is correct
44 Correct 2 ms 3028 KB Output is correct
45 Correct 2 ms 3028 KB Output is correct
46 Correct 2 ms 3044 KB Output is correct
47 Correct 2 ms 3028 KB Output is correct
48 Correct 2 ms 3028 KB Output is correct
49 Correct 1 ms 3040 KB Output is correct
50 Correct 1 ms 3028 KB Output is correct
51 Correct 1 ms 3028 KB Output is correct
52 Correct 1 ms 3028 KB Output is correct
53 Correct 2 ms 3028 KB Output is correct
54 Correct 2 ms 3028 KB Output is correct
55 Correct 2 ms 3028 KB Output is correct
56 Correct 2 ms 2980 KB Output is correct
57 Correct 42 ms 10864 KB Output is correct
58 Correct 39 ms 10724 KB Output is correct
59 Correct 41 ms 10824 KB Output is correct
60 Correct 41 ms 10572 KB Output is correct
61 Correct 39 ms 10932 KB Output is correct
62 Correct 46 ms 10760 KB Output is correct
63 Correct 36 ms 10568 KB Output is correct
64 Correct 36 ms 10584 KB Output is correct
65 Correct 37 ms 10884 KB Output is correct
66 Correct 37 ms 10880 KB Output is correct
67 Correct 39 ms 10876 KB Output is correct
68 Correct 39 ms 10820 KB Output is correct
69 Correct 40 ms 10896 KB Output is correct
70 Correct 42 ms 10820 KB Output is correct
71 Correct 2 ms 3028 KB Output is correct
72 Correct 2 ms 3184 KB Output is correct
73 Correct 2 ms 3236 KB Output is correct
74 Correct 3 ms 3284 KB Output is correct
75 Correct 3 ms 3284 KB Output is correct
76 Correct 2 ms 3284 KB Output is correct
77 Correct 2 ms 3284 KB Output is correct
78 Correct 2 ms 3284 KB Output is correct
79 Correct 2 ms 3284 KB Output is correct
80 Correct 39 ms 10868 KB Output is correct
81 Correct 39 ms 10836 KB Output is correct
82 Correct 52 ms 10888 KB Output is correct
83 Correct 38 ms 10952 KB Output is correct
84 Correct 2 ms 3156 KB Output is correct
85 Correct 2 ms 3156 KB Output is correct
86 Correct 2 ms 3156 KB Output is correct
87 Correct 2 ms 3156 KB Output is correct
88 Correct 2 ms 3156 KB Output is correct
89 Correct 2 ms 3156 KB Output is correct
90 Correct 2 ms 3156 KB Output is correct
91 Correct 2 ms 3284 KB Output is correct
92 Correct 2 ms 3188 KB Output is correct
93 Correct 2 ms 3188 KB Output is correct
94 Correct 2 ms 3028 KB Output is correct
95 Correct 2 ms 3028 KB Output is correct
96 Correct 1 ms 3028 KB Output is correct
97 Correct 1 ms 3044 KB Output is correct
98 Correct 1 ms 3028 KB Output is correct
99 Correct 2 ms 3028 KB Output is correct
100 Correct 2 ms 3028 KB Output is correct
101 Correct 2 ms 3028 KB Output is correct
102 Correct 1 ms 3028 KB Output is correct
103 Correct 2 ms 3028 KB Output is correct
104 Correct 7 ms 4052 KB Output is correct
105 Correct 12 ms 6160 KB Output is correct
106 Correct 2 ms 3028 KB Output is correct
107 Correct 21 ms 7692 KB Output is correct
108 Correct 21 ms 9712 KB Output is correct
109 Correct 2 ms 3028 KB Output is correct
110 Correct 34 ms 11724 KB Output is correct
111 Correct 35 ms 13944 KB Output is correct
112 Correct 2 ms 3156 KB Output is correct
113 Correct 48 ms 17996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 6080 KB Output is correct
2 Correct 13 ms 6100 KB Output is correct
3 Correct 13 ms 6100 KB Output is correct
4 Correct 13 ms 6128 KB Output is correct
5 Correct 13 ms 6100 KB Output is correct
6 Correct 13 ms 6216 KB Output is correct
7 Correct 20 ms 6356 KB Output is correct
8 Correct 13 ms 5972 KB Output is correct
9 Correct 13 ms 5928 KB Output is correct
10 Correct 13 ms 6100 KB Output is correct
11 Correct 1 ms 3028 KB Output is correct
12 Correct 3 ms 3796 KB Output is correct
13 Correct 5 ms 3864 KB Output is correct
14 Correct 3 ms 3796 KB Output is correct
15 Correct 3 ms 3796 KB Output is correct
16 Correct 3 ms 3796 KB Output is correct
17 Correct 3 ms 3796 KB Output is correct
18 Correct 3 ms 3796 KB Output is correct
19 Correct 3 ms 3796 KB Output is correct
20 Incorrect 1 ms 3028 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3028 KB Output is correct
2 Correct 2 ms 3048 KB Output is correct
3 Correct 1 ms 3028 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 2 ms 3028 KB Output is correct
6 Correct 1 ms 3028 KB Output is correct
7 Correct 2 ms 3028 KB Output is correct
8 Correct 2 ms 3028 KB Output is correct
9 Correct 1 ms 3028 KB Output is correct
10 Correct 2 ms 3028 KB Output is correct
11 Correct 2 ms 3028 KB Output is correct
12 Correct 1 ms 3048 KB Output is correct
13 Correct 1 ms 3028 KB Output is correct
14 Correct 2 ms 3028 KB Output is correct
15 Correct 2 ms 3028 KB Output is correct
16 Correct 2 ms 3028 KB Output is correct
17 Correct 2 ms 3080 KB Output is correct
18 Correct 2 ms 3052 KB Output is correct
19 Correct 2 ms 3044 KB Output is correct
20 Correct 2 ms 3028 KB Output is correct
21 Correct 2 ms 3028 KB Output is correct
22 Correct 1 ms 3028 KB Output is correct
23 Correct 2 ms 3028 KB Output is correct
24 Correct 2 ms 3048 KB Output is correct
25 Correct 1 ms 3028 KB Output is correct
26 Correct 2 ms 3028 KB Output is correct
27 Correct 2 ms 3156 KB Output is correct
28 Correct 2 ms 3156 KB Output is correct
29 Correct 2 ms 3028 KB Output is correct
30 Correct 2 ms 3156 KB Output is correct
31 Correct 3 ms 3436 KB Output is correct
32 Correct 2 ms 3028 KB Output is correct
33 Correct 2 ms 3156 KB Output is correct
34 Correct 2 ms 3156 KB Output is correct
35 Correct 2 ms 3028 KB Output is correct
36 Correct 3 ms 3028 KB Output is correct
37 Correct 2 ms 3028 KB Output is correct
38 Correct 2 ms 3028 KB Output is correct
39 Correct 2 ms 3044 KB Output is correct
40 Correct 1 ms 3156 KB Output is correct
41 Correct 2 ms 3028 KB Output is correct
42 Correct 1 ms 3028 KB Output is correct
43 Correct 1 ms 2968 KB Output is correct
44 Correct 2 ms 3156 KB Output is correct
45 Correct 2 ms 3028 KB Output is correct
46 Correct 1 ms 3028 KB Output is correct
47 Correct 3 ms 3028 KB Output is correct
48 Correct 2 ms 3028 KB Output is correct
49 Correct 1 ms 3044 KB Output is correct
50 Correct 2 ms 3028 KB Output is correct
51 Correct 2 ms 3048 KB Output is correct
52 Incorrect 2 ms 3028 KB Output isn't correct
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 15220 KB Output is correct
2 Correct 34 ms 16456 KB Output is correct
3 Correct 24 ms 12088 KB Output is correct
4 Correct 6 ms 5076 KB Output is correct
5 Correct 5 ms 4092 KB Output is correct
6 Correct 10 ms 6108 KB Output is correct
7 Correct 2 ms 3028 KB Output is correct
8 Correct 17 ms 7724 KB Output is correct
9 Correct 21 ms 9708 KB Output is correct
10 Correct 2 ms 3028 KB Output is correct
11 Correct 31 ms 11792 KB Output is correct
12 Correct 35 ms 13932 KB Output is correct
13 Correct 2 ms 3156 KB Output is correct
14 Correct 1 ms 3028 KB Output is correct
15 Correct 2 ms 3048 KB Output is correct
16 Correct 1 ms 3028 KB Output is correct
17 Correct 2 ms 3028 KB Output is correct
18 Correct 2 ms 3028 KB Output is correct
19 Correct 1 ms 3028 KB Output is correct
20 Correct 2 ms 3028 KB Output is correct
21 Correct 2 ms 3028 KB Output is correct
22 Correct 1 ms 3028 KB Output is correct
23 Correct 2 ms 3028 KB Output is correct
24 Correct 2 ms 3028 KB Output is correct
25 Correct 1 ms 3048 KB Output is correct
26 Correct 1 ms 3028 KB Output is correct
27 Correct 2 ms 3028 KB Output is correct
28 Correct 2 ms 3028 KB Output is correct
29 Correct 2 ms 3028 KB Output is correct
30 Correct 2 ms 3080 KB Output is correct
31 Correct 2 ms 3052 KB Output is correct
32 Correct 2 ms 3044 KB Output is correct
33 Correct 2 ms 3028 KB Output is correct
34 Correct 2 ms 3028 KB Output is correct
35 Correct 1 ms 3028 KB Output is correct
36 Correct 2 ms 3028 KB Output is correct
37 Correct 2 ms 3048 KB Output is correct
38 Correct 1 ms 3028 KB Output is correct
39 Correct 37 ms 16512 KB Output is correct
40 Correct 35 ms 16472 KB Output is correct
41 Correct 23 ms 12012 KB Output is correct
42 Correct 6 ms 5076 KB Output is correct
43 Correct 1 ms 3028 KB Output is correct
44 Correct 2 ms 3028 KB Output is correct
45 Correct 2 ms 3028 KB Output is correct
46 Correct 2 ms 3044 KB Output is correct
47 Correct 2 ms 3028 KB Output is correct
48 Correct 2 ms 3028 KB Output is correct
49 Correct 1 ms 3040 KB Output is correct
50 Correct 1 ms 3028 KB Output is correct
51 Correct 1 ms 3028 KB Output is correct
52 Correct 1 ms 3028 KB Output is correct
53 Correct 2 ms 3028 KB Output is correct
54 Correct 2 ms 3028 KB Output is correct
55 Correct 2 ms 3028 KB Output is correct
56 Correct 2 ms 2980 KB Output is correct
57 Correct 42 ms 10864 KB Output is correct
58 Correct 39 ms 10724 KB Output is correct
59 Correct 41 ms 10824 KB Output is correct
60 Correct 41 ms 10572 KB Output is correct
61 Correct 39 ms 10932 KB Output is correct
62 Correct 46 ms 10760 KB Output is correct
63 Correct 36 ms 10568 KB Output is correct
64 Correct 36 ms 10584 KB Output is correct
65 Correct 37 ms 10884 KB Output is correct
66 Correct 37 ms 10880 KB Output is correct
67 Correct 39 ms 10876 KB Output is correct
68 Correct 39 ms 10820 KB Output is correct
69 Correct 40 ms 10896 KB Output is correct
70 Correct 42 ms 10820 KB Output is correct
71 Correct 2 ms 3028 KB Output is correct
72 Correct 2 ms 3184 KB Output is correct
73 Correct 2 ms 3236 KB Output is correct
74 Correct 3 ms 3284 KB Output is correct
75 Correct 3 ms 3284 KB Output is correct
76 Correct 2 ms 3284 KB Output is correct
77 Correct 2 ms 3284 KB Output is correct
78 Correct 2 ms 3284 KB Output is correct
79 Correct 2 ms 3284 KB Output is correct
80 Correct 39 ms 10868 KB Output is correct
81 Correct 39 ms 10836 KB Output is correct
82 Correct 52 ms 10888 KB Output is correct
83 Correct 38 ms 10952 KB Output is correct
84 Correct 2 ms 3156 KB Output is correct
85 Correct 2 ms 3156 KB Output is correct
86 Correct 2 ms 3156 KB Output is correct
87 Correct 2 ms 3156 KB Output is correct
88 Correct 2 ms 3156 KB Output is correct
89 Correct 2 ms 3156 KB Output is correct
90 Correct 2 ms 3156 KB Output is correct
91 Correct 2 ms 3284 KB Output is correct
92 Correct 2 ms 3188 KB Output is correct
93 Correct 2 ms 3188 KB Output is correct
94 Correct 2 ms 3028 KB Output is correct
95 Correct 2 ms 3028 KB Output is correct
96 Correct 1 ms 3028 KB Output is correct
97 Correct 1 ms 3044 KB Output is correct
98 Correct 1 ms 3028 KB Output is correct
99 Correct 2 ms 3028 KB Output is correct
100 Correct 2 ms 3028 KB Output is correct
101 Correct 2 ms 3028 KB Output is correct
102 Correct 1 ms 3028 KB Output is correct
103 Correct 2 ms 3028 KB Output is correct
104 Correct 7 ms 4052 KB Output is correct
105 Correct 12 ms 6160 KB Output is correct
106 Correct 2 ms 3028 KB Output is correct
107 Correct 21 ms 7692 KB Output is correct
108 Correct 21 ms 9712 KB Output is correct
109 Correct 2 ms 3028 KB Output is correct
110 Correct 34 ms 11724 KB Output is correct
111 Correct 35 ms 13944 KB Output is correct
112 Correct 2 ms 3156 KB Output is correct
113 Correct 48 ms 17996 KB Output is correct
114 Correct 13 ms 6080 KB Output is correct
115 Correct 13 ms 6100 KB Output is correct
116 Correct 13 ms 6100 KB Output is correct
117 Correct 13 ms 6128 KB Output is correct
118 Correct 13 ms 6100 KB Output is correct
119 Correct 13 ms 6216 KB Output is correct
120 Correct 20 ms 6356 KB Output is correct
121 Correct 13 ms 5972 KB Output is correct
122 Correct 13 ms 5928 KB Output is correct
123 Correct 13 ms 6100 KB Output is correct
124 Correct 1 ms 3028 KB Output is correct
125 Correct 3 ms 3796 KB Output is correct
126 Correct 5 ms 3864 KB Output is correct
127 Correct 3 ms 3796 KB Output is correct
128 Correct 3 ms 3796 KB Output is correct
129 Correct 3 ms 3796 KB Output is correct
130 Correct 3 ms 3796 KB Output is correct
131 Correct 3 ms 3796 KB Output is correct
132 Correct 3 ms 3796 KB Output is correct
133 Incorrect 1 ms 3028 KB Output isn't correct
134 Halted 0 ms 0 KB -