Submission #1038481

# Submission time Handle Problem Language Result Execution time Memory
1038481 2024-07-29T20:55:03 Z ArthuroWich Dreaming (IOI13_dreaming) C++17
47 / 100
71 ms 19248 KB
#include "dreaming.h"
#include<bits/stdc++.h>
using namespace std;
vector<pair<long long int, long long int>> adj[100005];
long long int proc[100005], no, nod, dist[100005][2];
void dfs(long long int i, long long int p, long long int d) {
    if (d > nod) {
        no = i, nod = d;
    }
    proc[i] = 1;
    for (auto [j, w] : adj[i]) {
        if (j == p) {
            continue;
        }
        dfs(j, i, d+w);
    }
}
void dfsdist(long long int i, long long int p, long long int id) {
    for (auto [j, w] : adj[i]) {
        if (j == p) {
            continue;
        }
        dist[j][id] = dist[i][id]+w;
        dfsdist(j, i, id);
    }
}
void ch(long long int i, long long int p) {
    if (max(dist[i][0], dist[i][1]) < nod) {
        no = i, nod = max(dist[i][0], dist[i][1]);
    }
    for (auto [j, _] : adj[i]) {
        if (j == p) {
            continue;
        }
        ch(j, i);
    }
}
pair<long long int, long long int> calc(long long int i) {
    long long int a, b;
    no = i, nod = 0;
    dfs(i, -1, 0);
    a = no, no = i, nod = 0;
    dfs(a, -1, 0);
    b = no;
    dfsdist(a, -1, 0);
    dfsdist(b, -1, 1);
    no = i, nod = INT64_MAX;
    ch(i, -1);
    return {nod, no};
}
int travelTime(int n, int m, int l, int A[], int B[], int T[]) {
    vector<pair<long long int, long long int>> comp;
    for (long long 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 (long long int i = 0; i < n; i++) {
        if (proc[i]) {
            continue;
        }
        comp.push_back(calc(i));
    }
    sort(comp.rbegin(), comp.rend());
    deque<pair<long long int, long long int>> a;
    bool f = 0;
    for (long long int i = 0; i < comp.size(); i += 2) {
        if (f) {
            a.push_front(comp[i]);
            if (i+1 < comp.size()) {
                a.push_back(comp[i+1]);
            }
        } else {
            a.push_back(comp[i]);
            if (i+1 < comp.size()) {
                a.push_front(comp[i+1]);
            }
        }
        f ^= 1;
    }
    for (long long int i = 1; i < a.size(); i++) {
        adj[a[i-1].second].push_back({a[i].second, l});
        adj[a[i].second].push_back({a[i-1].second, l});
    }
    long long int a1, b1;
    no = 0, nod = 0;
    for (long long int i = 0; i < n; i++) {
        dist[i][0] = 0;
    }
    dfs(0, -1, 0);
    a1 = no, no = 0, nod = 0;
    dfs(a1, -1, 0);
    b1 = no;
    dfsdist(a1, -1, 0);
    return dist[b1][0];
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:66:33: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |     for (long long int i = 0; i < comp.size(); i += 2) {
      |                               ~~^~~~~~~~~~~~~
dreaming.cpp:69:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |             if (i+1 < comp.size()) {
      |                 ~~~~^~~~~~~~~~~~~
dreaming.cpp:74:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |             if (i+1 < comp.size()) {
      |                 ~~~~^~~~~~~~~~~~~
dreaming.cpp:80:33: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::deque<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |     for (long long int i = 1; i < a.size(); i++) {
      |                               ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 37 ms 17496 KB Output is correct
2 Correct 39 ms 17500 KB Output is correct
3 Correct 31 ms 13696 KB Output is correct
4 Correct 8 ms 7768 KB Output is correct
5 Correct 6 ms 7004 KB Output is correct
6 Correct 13 ms 8764 KB Output is correct
7 Correct 1 ms 5980 KB Output is correct
8 Correct 28 ms 10088 KB Output is correct
9 Correct 31 ms 11868 KB Output is correct
10 Correct 1 ms 5980 KB Output is correct
11 Correct 43 ms 13464 KB Output is correct
12 Correct 50 ms 15840 KB Output is correct
13 Correct 2 ms 6236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5980 KB Output is correct
2 Correct 1 ms 5980 KB Output is correct
3 Correct 1 ms 5980 KB Output is correct
4 Correct 1 ms 5980 KB Output is correct
5 Correct 1 ms 5980 KB Output is correct
6 Correct 1 ms 5980 KB Output is correct
7 Correct 1 ms 5980 KB Output is correct
8 Correct 1 ms 5980 KB Output is correct
9 Correct 1 ms 5980 KB Output is correct
10 Correct 1 ms 5980 KB Output is correct
11 Correct 1 ms 5980 KB Output is correct
12 Correct 1 ms 6072 KB Output is correct
13 Correct 1 ms 5976 KB Output is correct
14 Correct 1 ms 5980 KB Output is correct
15 Correct 1 ms 3932 KB Output is correct
16 Correct 1 ms 5980 KB Output is correct
17 Correct 1 ms 5980 KB Output is correct
18 Correct 1 ms 5980 KB Output is correct
19 Correct 1 ms 5980 KB Output is correct
20 Correct 1 ms 6076 KB Output is correct
21 Correct 1 ms 6232 KB Output is correct
22 Correct 2 ms 5980 KB Output is correct
23 Correct 1 ms 5980 KB Output is correct
24 Correct 1 ms 5980 KB Output is correct
25 Correct 2 ms 5980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 17496 KB Output is correct
2 Correct 39 ms 17500 KB Output is correct
3 Correct 31 ms 13696 KB Output is correct
4 Correct 8 ms 7768 KB Output is correct
5 Correct 6 ms 7004 KB Output is correct
6 Correct 13 ms 8764 KB Output is correct
7 Correct 1 ms 5980 KB Output is correct
8 Correct 28 ms 10088 KB Output is correct
9 Correct 31 ms 11868 KB Output is correct
10 Correct 1 ms 5980 KB Output is correct
11 Correct 43 ms 13464 KB Output is correct
12 Correct 50 ms 15840 KB Output is correct
13 Correct 2 ms 6236 KB Output is correct
14 Correct 1 ms 5980 KB Output is correct
15 Correct 1 ms 5980 KB Output is correct
16 Correct 1 ms 5980 KB Output is correct
17 Correct 1 ms 5980 KB Output is correct
18 Correct 1 ms 5980 KB Output is correct
19 Correct 1 ms 5980 KB Output is correct
20 Correct 1 ms 5980 KB Output is correct
21 Correct 1 ms 5980 KB Output is correct
22 Correct 1 ms 5980 KB Output is correct
23 Correct 1 ms 5980 KB Output is correct
24 Correct 1 ms 5980 KB Output is correct
25 Correct 1 ms 6072 KB Output is correct
26 Correct 1 ms 5976 KB Output is correct
27 Correct 1 ms 5980 KB Output is correct
28 Correct 1 ms 3932 KB Output is correct
29 Correct 1 ms 5980 KB Output is correct
30 Correct 1 ms 5980 KB Output is correct
31 Correct 1 ms 5980 KB Output is correct
32 Correct 1 ms 5980 KB Output is correct
33 Correct 1 ms 6076 KB Output is correct
34 Correct 1 ms 6232 KB Output is correct
35 Correct 2 ms 5980 KB Output is correct
36 Correct 1 ms 5980 KB Output is correct
37 Correct 1 ms 5980 KB Output is correct
38 Correct 2 ms 5980 KB Output is correct
39 Correct 43 ms 17492 KB Output is correct
40 Correct 40 ms 17488 KB Output is correct
41 Correct 26 ms 13556 KB Output is correct
42 Correct 6 ms 7664 KB Output is correct
43 Correct 1 ms 5980 KB Output is correct
44 Correct 1 ms 5980 KB Output is correct
45 Correct 2 ms 5980 KB Output is correct
46 Correct 1 ms 5980 KB Output is correct
47 Correct 2 ms 5980 KB Output is correct
48 Correct 1 ms 5980 KB Output is correct
49 Correct 1 ms 5980 KB Output is correct
50 Correct 1 ms 5980 KB Output is correct
51 Correct 1 ms 5980 KB Output is correct
52 Correct 1 ms 5980 KB Output is correct
53 Correct 2 ms 5976 KB Output is correct
54 Correct 1 ms 5976 KB Output is correct
55 Correct 1 ms 5976 KB Output is correct
56 Correct 1 ms 5980 KB Output is correct
57 Correct 52 ms 12116 KB Output is correct
58 Correct 51 ms 12172 KB Output is correct
59 Correct 55 ms 11868 KB Output is correct
60 Correct 66 ms 11856 KB Output is correct
61 Correct 49 ms 11608 KB Output is correct
62 Correct 50 ms 11612 KB Output is correct
63 Correct 56 ms 11448 KB Output is correct
64 Correct 47 ms 11432 KB Output is correct
65 Correct 61 ms 11348 KB Output is correct
66 Correct 48 ms 11352 KB Output is correct
67 Correct 55 ms 11936 KB Output is correct
68 Correct 62 ms 11856 KB Output is correct
69 Correct 60 ms 11868 KB Output is correct
70 Correct 55 ms 11904 KB Output is correct
71 Correct 2 ms 3932 KB Output is correct
72 Correct 2 ms 6236 KB Output is correct
73 Correct 2 ms 6236 KB Output is correct
74 Correct 2 ms 6236 KB Output is correct
75 Correct 2 ms 6236 KB Output is correct
76 Correct 2 ms 6236 KB Output is correct
77 Correct 2 ms 6236 KB Output is correct
78 Correct 2 ms 6236 KB Output is correct
79 Correct 2 ms 6236 KB Output is correct
80 Correct 55 ms 11896 KB Output is correct
81 Correct 58 ms 11868 KB Output is correct
82 Correct 59 ms 11716 KB Output is correct
83 Correct 49 ms 11720 KB Output is correct
84 Correct 2 ms 6232 KB Output is correct
85 Correct 2 ms 6236 KB Output is correct
86 Correct 2 ms 6236 KB Output is correct
87 Correct 2 ms 6236 KB Output is correct
88 Correct 2 ms 6104 KB Output is correct
89 Correct 2 ms 6236 KB Output is correct
90 Correct 2 ms 6236 KB Output is correct
91 Correct 2 ms 6236 KB Output is correct
92 Correct 2 ms 6288 KB Output is correct
93 Correct 2 ms 6236 KB Output is correct
94 Correct 1 ms 5980 KB Output is correct
95 Correct 1 ms 5980 KB Output is correct
96 Correct 1 ms 5980 KB Output is correct
97 Correct 2 ms 5980 KB Output is correct
98 Correct 1 ms 5980 KB Output is correct
99 Correct 1 ms 5980 KB Output is correct
100 Correct 1 ms 5980 KB Output is correct
101 Correct 1 ms 5980 KB Output is correct
102 Correct 1 ms 5976 KB Output is correct
103 Correct 1 ms 5976 KB Output is correct
104 Correct 6 ms 7256 KB Output is correct
105 Correct 13 ms 8796 KB Output is correct
106 Correct 1 ms 5980 KB Output is correct
107 Correct 28 ms 10076 KB Output is correct
108 Correct 38 ms 11816 KB Output is correct
109 Correct 2 ms 5976 KB Output is correct
110 Correct 45 ms 13620 KB Output is correct
111 Correct 50 ms 15648 KB Output is correct
112 Correct 2 ms 6232 KB Output is correct
113 Correct 71 ms 19248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 18528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5980 KB Output is correct
2 Correct 1 ms 5980 KB Output is correct
3 Correct 1 ms 5980 KB Output is correct
4 Correct 1 ms 5980 KB Output is correct
5 Correct 1 ms 5980 KB Output is correct
6 Correct 1 ms 5980 KB Output is correct
7 Correct 1 ms 5980 KB Output is correct
8 Correct 1 ms 5980 KB Output is correct
9 Correct 1 ms 5980 KB Output is correct
10 Correct 1 ms 5980 KB Output is correct
11 Correct 1 ms 5980 KB Output is correct
12 Correct 1 ms 6072 KB Output is correct
13 Correct 1 ms 5976 KB Output is correct
14 Correct 1 ms 5980 KB Output is correct
15 Correct 1 ms 3932 KB Output is correct
16 Correct 1 ms 5980 KB Output is correct
17 Correct 1 ms 5980 KB Output is correct
18 Correct 1 ms 5980 KB Output is correct
19 Correct 1 ms 5980 KB Output is correct
20 Correct 1 ms 6076 KB Output is correct
21 Correct 1 ms 6232 KB Output is correct
22 Correct 2 ms 5980 KB Output is correct
23 Correct 1 ms 5980 KB Output is correct
24 Correct 1 ms 5980 KB Output is correct
25 Correct 2 ms 5980 KB Output is correct
26 Correct 1 ms 5976 KB Output is correct
27 Incorrect 2 ms 6236 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 37 ms 17496 KB Output is correct
2 Correct 39 ms 17500 KB Output is correct
3 Correct 31 ms 13696 KB Output is correct
4 Correct 8 ms 7768 KB Output is correct
5 Correct 6 ms 7004 KB Output is correct
6 Correct 13 ms 8764 KB Output is correct
7 Correct 1 ms 5980 KB Output is correct
8 Correct 28 ms 10088 KB Output is correct
9 Correct 31 ms 11868 KB Output is correct
10 Correct 1 ms 5980 KB Output is correct
11 Correct 43 ms 13464 KB Output is correct
12 Correct 50 ms 15840 KB Output is correct
13 Correct 2 ms 6236 KB Output is correct
14 Correct 1 ms 5980 KB Output is correct
15 Correct 1 ms 5980 KB Output is correct
16 Correct 1 ms 5980 KB Output is correct
17 Correct 1 ms 5980 KB Output is correct
18 Correct 1 ms 5980 KB Output is correct
19 Correct 1 ms 5980 KB Output is correct
20 Correct 1 ms 5980 KB Output is correct
21 Correct 1 ms 5980 KB Output is correct
22 Correct 1 ms 5980 KB Output is correct
23 Correct 1 ms 5980 KB Output is correct
24 Correct 1 ms 5980 KB Output is correct
25 Correct 1 ms 6072 KB Output is correct
26 Correct 1 ms 5976 KB Output is correct
27 Correct 1 ms 5980 KB Output is correct
28 Correct 1 ms 3932 KB Output is correct
29 Correct 1 ms 5980 KB Output is correct
30 Correct 1 ms 5980 KB Output is correct
31 Correct 1 ms 5980 KB Output is correct
32 Correct 1 ms 5980 KB Output is correct
33 Correct 1 ms 6076 KB Output is correct
34 Correct 1 ms 6232 KB Output is correct
35 Correct 2 ms 5980 KB Output is correct
36 Correct 1 ms 5980 KB Output is correct
37 Correct 1 ms 5980 KB Output is correct
38 Correct 2 ms 5980 KB Output is correct
39 Correct 43 ms 17492 KB Output is correct
40 Correct 40 ms 17488 KB Output is correct
41 Correct 26 ms 13556 KB Output is correct
42 Correct 6 ms 7664 KB Output is correct
43 Correct 1 ms 5980 KB Output is correct
44 Correct 1 ms 5980 KB Output is correct
45 Correct 2 ms 5980 KB Output is correct
46 Correct 1 ms 5980 KB Output is correct
47 Correct 2 ms 5980 KB Output is correct
48 Correct 1 ms 5980 KB Output is correct
49 Correct 1 ms 5980 KB Output is correct
50 Correct 1 ms 5980 KB Output is correct
51 Correct 1 ms 5980 KB Output is correct
52 Correct 1 ms 5980 KB Output is correct
53 Correct 2 ms 5976 KB Output is correct
54 Correct 1 ms 5976 KB Output is correct
55 Correct 1 ms 5976 KB Output is correct
56 Correct 1 ms 5980 KB Output is correct
57 Correct 52 ms 12116 KB Output is correct
58 Correct 51 ms 12172 KB Output is correct
59 Correct 55 ms 11868 KB Output is correct
60 Correct 66 ms 11856 KB Output is correct
61 Correct 49 ms 11608 KB Output is correct
62 Correct 50 ms 11612 KB Output is correct
63 Correct 56 ms 11448 KB Output is correct
64 Correct 47 ms 11432 KB Output is correct
65 Correct 61 ms 11348 KB Output is correct
66 Correct 48 ms 11352 KB Output is correct
67 Correct 55 ms 11936 KB Output is correct
68 Correct 62 ms 11856 KB Output is correct
69 Correct 60 ms 11868 KB Output is correct
70 Correct 55 ms 11904 KB Output is correct
71 Correct 2 ms 3932 KB Output is correct
72 Correct 2 ms 6236 KB Output is correct
73 Correct 2 ms 6236 KB Output is correct
74 Correct 2 ms 6236 KB Output is correct
75 Correct 2 ms 6236 KB Output is correct
76 Correct 2 ms 6236 KB Output is correct
77 Correct 2 ms 6236 KB Output is correct
78 Correct 2 ms 6236 KB Output is correct
79 Correct 2 ms 6236 KB Output is correct
80 Correct 55 ms 11896 KB Output is correct
81 Correct 58 ms 11868 KB Output is correct
82 Correct 59 ms 11716 KB Output is correct
83 Correct 49 ms 11720 KB Output is correct
84 Correct 2 ms 6232 KB Output is correct
85 Correct 2 ms 6236 KB Output is correct
86 Correct 2 ms 6236 KB Output is correct
87 Correct 2 ms 6236 KB Output is correct
88 Correct 2 ms 6104 KB Output is correct
89 Correct 2 ms 6236 KB Output is correct
90 Correct 2 ms 6236 KB Output is correct
91 Correct 2 ms 6236 KB Output is correct
92 Correct 2 ms 6288 KB Output is correct
93 Correct 2 ms 6236 KB Output is correct
94 Correct 1 ms 5980 KB Output is correct
95 Correct 1 ms 5980 KB Output is correct
96 Correct 1 ms 5980 KB Output is correct
97 Correct 2 ms 5980 KB Output is correct
98 Correct 1 ms 5980 KB Output is correct
99 Correct 1 ms 5980 KB Output is correct
100 Correct 1 ms 5980 KB Output is correct
101 Correct 1 ms 5980 KB Output is correct
102 Correct 1 ms 5976 KB Output is correct
103 Correct 1 ms 5976 KB Output is correct
104 Correct 6 ms 7256 KB Output is correct
105 Correct 13 ms 8796 KB Output is correct
106 Correct 1 ms 5980 KB Output is correct
107 Correct 28 ms 10076 KB Output is correct
108 Correct 38 ms 11816 KB Output is correct
109 Correct 2 ms 5976 KB Output is correct
110 Correct 45 ms 13620 KB Output is correct
111 Correct 50 ms 15648 KB Output is correct
112 Correct 2 ms 6232 KB Output is correct
113 Correct 71 ms 19248 KB Output is correct
114 Incorrect 34 ms 18528 KB Output isn't correct
115 Halted 0 ms 0 KB -