Submission #1038938

# Submission time Handle Problem Language Result Execution time Memory
1038938 2024-07-30T09:46:29 Z HappyCapybara Dreaming (IOI13_dreaming) C++17
47 / 100
44 ms 11032 KB
#include "dreaming.h"
#include<bits/stdc++.h>
using namespace std;

vector<int> p, s;

int findp(int a){
    if (p[a] == a) return p[a];
    return p[a] = findp(p[a]);
}

void merge(int a, int b){
    a = findp(a);
    b = findp(b);
    if (a == b) return;
    p[b] = a;
    s[a] += s[b];
    s[b] == 0;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]){
    p.resize(N);
    for (int i=0; i<N; i++) p[i] = i;
    s.resize(N, 1);
    vector<vector<pair<int,int>>> g(N);
    for (int i=0; i<M; i++){
        merge(A[i], B[i]);
        g[A[i]].push_back({B[i], T[i]});
        g[B[i]].push_back({A[i], T[i]});
    }
    vector<int> dm, r;
    vector<bool> done(N, false), seen(N, false);
    vector<int> tp(N, -1), td(N);
    for (int i=0; i<N; i++){
        int j = findp(i);
        if (done[j]) continue;
        done[j] = true;
        if (s[j] == 1){
            dm.push_back(0);
            r.push_back(0);
            continue;
        }
        queue<pair<int,int>> q;
        q.push({j, 0});
        int ft = j, md = 0;
        while (!q.empty()){
            int cur = q.front().first, d = q.front().second;
            q.pop();
            if (seen[cur]) continue;
            seen[cur] = true;
            if (d > md){
                md = d;
                ft = cur;
            }
            for (pair<int,int> next : g[cur]) q.push({next.first, d+next.second});
        }
        tp[ft] = ft;
        td[ft] = 0;
        int ft2 = ft;
        md = 0;
        q.push({ft, 0});
        while (!q.empty()){
            int cur = q.front().first, d = q.front().second;
            q.pop();
            td[cur] = d;
            if (d > md){
                md = d;
                ft2 = cur;
            }
            for (pair<int,int> next : g[cur]){
                if (tp[next.first] == -1){
                    tp[next.first] = cur;
                    q.push({next.first, d+next.second});
                }
            }
        }
        dm.push_back(md);
        int br = md;
        while (ft2 != ft){
            br = min(br, max(td[ft2], md-td[ft2]));
            ft2 = tp[ft2];
        }
        r.push_back(br);
    }

    int res = 0;
    for (int x : dm) res = max(res, x);
    if (r.size() == 2) res = max(res, r[0]+r[1]+L);
    else {
        sort(r.begin(), r.end());
        res = max(res, r[r.size()-1]+r[r.size()-2]+L);
        res = max(res, r[r.size()-2]+r[r.size()-3]+2*L);
    }
    return res;
}

Compilation message

dreaming.cpp: In function 'void merge(int, int)':
dreaming.cpp:18:10: warning: value computed is not used [-Wunused-value]
   18 |     s[b] == 0;
# Verdict Execution time Memory Grader output
1 Correct 32 ms 9052 KB Output is correct
2 Correct 31 ms 9052 KB Output is correct
3 Correct 21 ms 6204 KB Output is correct
4 Correct 4 ms 1628 KB Output is correct
5 Correct 4 ms 1372 KB Output is correct
6 Correct 8 ms 2392 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 16 ms 4296 KB Output is correct
9 Correct 21 ms 5180 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 30 ms 7252 KB Output is correct
12 Correct 35 ms 8036 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 444 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 9052 KB Output is correct
2 Correct 31 ms 9052 KB Output is correct
3 Correct 21 ms 6204 KB Output is correct
4 Correct 4 ms 1628 KB Output is correct
5 Correct 4 ms 1372 KB Output is correct
6 Correct 8 ms 2392 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 16 ms 4296 KB Output is correct
9 Correct 21 ms 5180 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 30 ms 7252 KB Output is correct
12 Correct 35 ms 8036 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 444 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 35 ms 9204 KB Output is correct
40 Correct 36 ms 9044 KB Output is correct
41 Correct 23 ms 6232 KB Output is correct
42 Correct 4 ms 1628 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 344 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 440 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 39 ms 10836 KB Output is correct
58 Correct 40 ms 10832 KB Output is correct
59 Correct 39 ms 10580 KB Output is correct
60 Correct 42 ms 10680 KB Output is correct
61 Correct 39 ms 10836 KB Output is correct
62 Correct 39 ms 10844 KB Output is correct
63 Correct 35 ms 10668 KB Output is correct
64 Correct 36 ms 10664 KB Output is correct
65 Correct 38 ms 10836 KB Output is correct
66 Correct 35 ms 11032 KB Output is correct
67 Correct 38 ms 10588 KB Output is correct
68 Correct 37 ms 10556 KB Output is correct
69 Correct 39 ms 10844 KB Output is correct
70 Correct 39 ms 10840 KB Output is correct
71 Correct 0 ms 344 KB Output is correct
72 Correct 1 ms 604 KB Output is correct
73 Correct 1 ms 604 KB Output is correct
74 Correct 1 ms 604 KB Output is correct
75 Correct 1 ms 604 KB Output is correct
76 Correct 1 ms 860 KB Output is correct
77 Correct 1 ms 604 KB Output is correct
78 Correct 1 ms 604 KB Output is correct
79 Correct 2 ms 604 KB Output is correct
80 Correct 40 ms 10692 KB Output is correct
81 Correct 38 ms 10588 KB Output is correct
82 Correct 40 ms 10844 KB Output is correct
83 Correct 44 ms 10840 KB Output is correct
84 Correct 1 ms 452 KB Output is correct
85 Correct 1 ms 604 KB Output is correct
86 Correct 1 ms 604 KB Output is correct
87 Correct 1 ms 604 KB Output is correct
88 Correct 1 ms 600 KB Output is correct
89 Correct 1 ms 492 KB Output is correct
90 Correct 1 ms 604 KB Output is correct
91 Correct 1 ms 608 KB Output is correct
92 Correct 1 ms 688 KB Output is correct
93 Correct 1 ms 604 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 0 ms 348 KB Output is correct
98 Correct 0 ms 348 KB Output is correct
99 Correct 0 ms 348 KB Output is correct
100 Correct 0 ms 348 KB Output is correct
101 Correct 0 ms 348 KB Output is correct
102 Correct 0 ms 360 KB Output is correct
103 Correct 0 ms 604 KB Output is correct
104 Correct 4 ms 1192 KB Output is correct
105 Correct 9 ms 2396 KB Output is correct
106 Correct 0 ms 348 KB Output is correct
107 Correct 16 ms 4168 KB Output is correct
108 Correct 21 ms 5212 KB Output is correct
109 Correct 0 ms 348 KB Output is correct
110 Correct 31 ms 7388 KB Output is correct
111 Correct 34 ms 8028 KB Output is correct
112 Correct 1 ms 348 KB Output is correct
113 Correct 43 ms 10188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 7384 KB Output is correct
2 Correct 22 ms 7560 KB Output is correct
3 Correct 25 ms 7384 KB Output is correct
4 Correct 18 ms 7380 KB Output is correct
5 Correct 18 ms 7384 KB Output is correct
6 Correct 22 ms 8044 KB Output is correct
7 Correct 19 ms 7856 KB Output is correct
8 Correct 21 ms 7384 KB Output is correct
9 Correct 18 ms 7348 KB Output is correct
10 Correct 19 ms 7640 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 5428 KB Output is correct
13 Correct 4 ms 5440 KB Output is correct
14 Correct 4 ms 5256 KB Output is correct
15 Correct 4 ms 5336 KB Output is correct
16 Correct 4 ms 5256 KB Output is correct
17 Correct 4 ms 5256 KB Output is correct
18 Correct 4 ms 5336 KB Output is correct
19 Correct 4 ms 5332 KB Output is correct
20 Incorrect 1 ms 344 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 444 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 456 KB Output is correct
34 Correct 1 ms 856 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 440 KB Output is correct
47 Correct 0 ms 344 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Incorrect 0 ms 348 KB Output isn't correct
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 9052 KB Output is correct
2 Correct 31 ms 9052 KB Output is correct
3 Correct 21 ms 6204 KB Output is correct
4 Correct 4 ms 1628 KB Output is correct
5 Correct 4 ms 1372 KB Output is correct
6 Correct 8 ms 2392 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 16 ms 4296 KB Output is correct
9 Correct 21 ms 5180 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 30 ms 7252 KB Output is correct
12 Correct 35 ms 8036 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 444 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 35 ms 9204 KB Output is correct
40 Correct 36 ms 9044 KB Output is correct
41 Correct 23 ms 6232 KB Output is correct
42 Correct 4 ms 1628 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 344 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 440 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 39 ms 10836 KB Output is correct
58 Correct 40 ms 10832 KB Output is correct
59 Correct 39 ms 10580 KB Output is correct
60 Correct 42 ms 10680 KB Output is correct
61 Correct 39 ms 10836 KB Output is correct
62 Correct 39 ms 10844 KB Output is correct
63 Correct 35 ms 10668 KB Output is correct
64 Correct 36 ms 10664 KB Output is correct
65 Correct 38 ms 10836 KB Output is correct
66 Correct 35 ms 11032 KB Output is correct
67 Correct 38 ms 10588 KB Output is correct
68 Correct 37 ms 10556 KB Output is correct
69 Correct 39 ms 10844 KB Output is correct
70 Correct 39 ms 10840 KB Output is correct
71 Correct 0 ms 344 KB Output is correct
72 Correct 1 ms 604 KB Output is correct
73 Correct 1 ms 604 KB Output is correct
74 Correct 1 ms 604 KB Output is correct
75 Correct 1 ms 604 KB Output is correct
76 Correct 1 ms 860 KB Output is correct
77 Correct 1 ms 604 KB Output is correct
78 Correct 1 ms 604 KB Output is correct
79 Correct 2 ms 604 KB Output is correct
80 Correct 40 ms 10692 KB Output is correct
81 Correct 38 ms 10588 KB Output is correct
82 Correct 40 ms 10844 KB Output is correct
83 Correct 44 ms 10840 KB Output is correct
84 Correct 1 ms 452 KB Output is correct
85 Correct 1 ms 604 KB Output is correct
86 Correct 1 ms 604 KB Output is correct
87 Correct 1 ms 604 KB Output is correct
88 Correct 1 ms 600 KB Output is correct
89 Correct 1 ms 492 KB Output is correct
90 Correct 1 ms 604 KB Output is correct
91 Correct 1 ms 608 KB Output is correct
92 Correct 1 ms 688 KB Output is correct
93 Correct 1 ms 604 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 0 ms 348 KB Output is correct
98 Correct 0 ms 348 KB Output is correct
99 Correct 0 ms 348 KB Output is correct
100 Correct 0 ms 348 KB Output is correct
101 Correct 0 ms 348 KB Output is correct
102 Correct 0 ms 360 KB Output is correct
103 Correct 0 ms 604 KB Output is correct
104 Correct 4 ms 1192 KB Output is correct
105 Correct 9 ms 2396 KB Output is correct
106 Correct 0 ms 348 KB Output is correct
107 Correct 16 ms 4168 KB Output is correct
108 Correct 21 ms 5212 KB Output is correct
109 Correct 0 ms 348 KB Output is correct
110 Correct 31 ms 7388 KB Output is correct
111 Correct 34 ms 8028 KB Output is correct
112 Correct 1 ms 348 KB Output is correct
113 Correct 43 ms 10188 KB Output is correct
114 Correct 22 ms 7384 KB Output is correct
115 Correct 22 ms 7560 KB Output is correct
116 Correct 25 ms 7384 KB Output is correct
117 Correct 18 ms 7380 KB Output is correct
118 Correct 18 ms 7384 KB Output is correct
119 Correct 22 ms 8044 KB Output is correct
120 Correct 19 ms 7856 KB Output is correct
121 Correct 21 ms 7384 KB Output is correct
122 Correct 18 ms 7348 KB Output is correct
123 Correct 19 ms 7640 KB Output is correct
124 Correct 0 ms 348 KB Output is correct
125 Correct 5 ms 5428 KB Output is correct
126 Correct 4 ms 5440 KB Output is correct
127 Correct 4 ms 5256 KB Output is correct
128 Correct 4 ms 5336 KB Output is correct
129 Correct 4 ms 5256 KB Output is correct
130 Correct 4 ms 5256 KB Output is correct
131 Correct 4 ms 5336 KB Output is correct
132 Correct 4 ms 5332 KB Output is correct
133 Incorrect 1 ms 344 KB Output isn't correct
134 Halted 0 ms 0 KB -