Submission #250981

# Submission time Handle Problem Language Result Execution time Memory
250981 2020-07-19T17:47:27 Z A02 Dreaming (IOI13_dreaming) C++14
47 / 100
1000 ms 29544 KB
#include "dreaming.h"
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;

pair<long long, long long> calc_centre(int start, vector<vector<pair<long long, long long> > > &adjacent){


    queue<long long> to_visit;
    to_visit.push(start);

    map<long long, long long> distances1;
    distances1[start] = 0;

    long long longest_distance = 0;
    long long endpoint = start;

    while (!to_visit.empty()){

            long long current = to_visit.front();
            if (longest_distance < distances1[current]){
                longest_distance = distances1[current];
                endpoint = current;
            }

            to_visit.pop();

            for (int j = 0; j < adjacent[current].size(); j++){
                if (distances1.find(adjacent[current][j].first) == distances1.end()){
                    distances1[adjacent[current][j].first] = distances1[current] + adjacent[current][j].second;
                    to_visit.push(adjacent[current][j].first);
                }
            }
    }


    map<long long, long long> distances;
    map<long long, long long> parent;
    parent[endpoint] = endpoint;

    to_visit.push(endpoint);

    longest_distance = 0;
    long long startpoint = endpoint;

    while (!to_visit.empty()){

            long long current = to_visit.front();

            if (longest_distance < distances[current]){
                longest_distance = distances[current];
                startpoint = current;
            }

            to_visit.pop();

            for (long long j = 0; j < adjacent[current].size(); j++){
                if (distances.find(adjacent[current][j].first) == distances.end()){
                    distances[adjacent[current][j].first] = distances[current] + adjacent[current][j].second;
                    to_visit.push(adjacent[current][j].first);
                    parent[adjacent[current][j].first] = current;
                }
            }
    }

    long long radius = longest_distance;

    long long current = startpoint;

    long long left_distance = longest_distance;
    long long right_distance = 0;
    long long best = startpoint;

    while (current != endpoint){
        if(radius > max(left_distance, right_distance)){
            radius = max(left_distance, right_distance);
            best = current;
        }

        current = parent[current];
        left_distance = distances[current];
        right_distance = longest_distance - left_distance;

    }

    return make_pair(longest_distance, best);

}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {

    vector<vector<pair<long long, long long> > > adjacent (N, vector<pair<long long, long long> > ());

    for (int i = 0; i < M; i++){
        adjacent[A[i]].push_back(make_pair(B[i], T[i]));
        adjacent[B[i]].push_back(make_pair(A[i], T[i]));
    }

    vector<long long> region (N, -1);
    long long current_region = 0;
    vector<pair<long long, long long> > radii;

    for (int i = 0; i < N; i++){
        if (region[i] == -1){

            radii.push_back(calc_centre(i, adjacent));

            queue<long long> to_visit;
            to_visit.push(i);

            while (!to_visit.empty()){

                long long current = to_visit.front();
                to_visit.pop();
                region[current] = current_region;

                for (long long j = 0; j < adjacent[current].size(); j++){
                    if (region[adjacent[current][j].first] == -1){
                        to_visit.push(adjacent[current][j].first);
                    }
                }

            }


            current_region++;
        }

    }

    while (radii.size() > 1){

        pair<long long, long long > a1 = radii[radii.size() - 1];
        pair<long long, long long > a2 = radii[radii.size() - 2];
        radii.pop_back();
        radii.pop_back();

        long long x = a1.second;
        long long y = a2.second;
        adjacent[x].push_back(make_pair(y, L));
        adjacent[y].push_back(make_pair(x, L));
        //cout << x << ' ' << y << endl;
        radii.push_back(calc_centre(x, adjacent));


    }


    return radii[0].first;
}

Compilation message

dreaming.cpp: In function 'std::pair<long long int, long long int> calc_centre(int, std::vector<std::vector<std::pair<long long int, long long int> > >&)':
dreaming.cpp:33:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int j = 0; j < adjacent[current].size(); j++){
                             ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
dreaming.cpp:62:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (long long j = 0; j < adjacent[current].size(); j++){
                                   ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:122:41: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (long long j = 0; j < adjacent[current].size(); j++){
                                       ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 851 ms 26104 KB Output is correct
2 Correct 786 ms 25864 KB Output is correct
3 Correct 432 ms 17016 KB Output is correct
4 Correct 63 ms 4132 KB Output is correct
5 Correct 44 ms 3200 KB Output is correct
6 Correct 112 ms 6160 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 246 ms 11776 KB Output is correct
9 Correct 291 ms 14672 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 539 ms 20472 KB Output is correct
12 Correct 613 ms 23348 KB Output is correct
13 Correct 3 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 851 ms 26104 KB Output is correct
2 Correct 786 ms 25864 KB Output is correct
3 Correct 432 ms 17016 KB Output is correct
4 Correct 63 ms 4132 KB Output is correct
5 Correct 44 ms 3200 KB Output is correct
6 Correct 112 ms 6160 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 246 ms 11776 KB Output is correct
9 Correct 291 ms 14672 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 539 ms 20472 KB Output is correct
12 Correct 613 ms 23348 KB Output is correct
13 Correct 3 ms 640 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 0 ms 256 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 851 ms 26104 KB Output is correct
2 Correct 786 ms 25864 KB Output is correct
3 Correct 432 ms 17016 KB Output is correct
4 Correct 63 ms 4132 KB Output is correct
5 Correct 44 ms 3200 KB Output is correct
6 Correct 112 ms 6160 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 246 ms 11776 KB Output is correct
9 Correct 291 ms 14672 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 539 ms 20472 KB Output is correct
12 Correct 613 ms 23348 KB Output is correct
13 Correct 3 ms 640 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 0 ms 256 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 917 ms 26104 KB Output is correct
40 Correct 689 ms 25856 KB Output is correct
41 Correct 443 ms 17272 KB Output is correct
42 Correct 64 ms 4260 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 1 ms 360 KB Output is correct
51 Correct 1 ms 384 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 1 ms 384 KB Output is correct
54 Correct 1 ms 384 KB Output is correct
55 Correct 1 ms 384 KB Output is correct
56 Correct 1 ms 384 KB Output is correct
57 Correct 784 ms 29508 KB Output is correct
58 Correct 740 ms 29544 KB Output is correct
59 Correct 870 ms 29268 KB Output is correct
60 Correct 790 ms 29040 KB Output is correct
61 Correct 840 ms 29048 KB Output is correct
62 Correct 912 ms 29128 KB Output is correct
63 Correct 888 ms 29192 KB Output is correct
64 Correct 895 ms 28972 KB Output is correct
65 Correct 849 ms 28924 KB Output is correct
66 Correct 847 ms 29052 KB Output is correct
67 Correct 805 ms 29144 KB Output is correct
68 Correct 786 ms 29132 KB Output is correct
69 Correct 799 ms 29188 KB Output is correct
70 Correct 751 ms 29112 KB Output is correct
71 Correct 1 ms 384 KB Output is correct
72 Correct 10 ms 1152 KB Output is correct
73 Correct 10 ms 1152 KB Output is correct
74 Correct 10 ms 1152 KB Output is correct
75 Correct 10 ms 1152 KB Output is correct
76 Correct 10 ms 1152 KB Output is correct
77 Correct 12 ms 1196 KB Output is correct
78 Correct 11 ms 1200 KB Output is correct
79 Correct 13 ms 1152 KB Output is correct
80 Correct 851 ms 29116 KB Output is correct
81 Correct 873 ms 29072 KB Output is correct
82 Correct 835 ms 29076 KB Output is correct
83 Correct 846 ms 29120 KB Output is correct
84 Correct 8 ms 1024 KB Output is correct
85 Correct 6 ms 948 KB Output is correct
86 Correct 8 ms 1152 KB Output is correct
87 Correct 9 ms 1056 KB Output is correct
88 Correct 8 ms 1160 KB Output is correct
89 Correct 9 ms 1052 KB Output is correct
90 Correct 9 ms 1144 KB Output is correct
91 Correct 10 ms 1152 KB Output is correct
92 Correct 10 ms 1284 KB Output is correct
93 Correct 9 ms 1152 KB Output is correct
94 Correct 1 ms 384 KB Output is correct
95 Correct 1 ms 384 KB Output is correct
96 Correct 1 ms 384 KB Output is correct
97 Correct 1 ms 384 KB Output is correct
98 Correct 1 ms 384 KB Output is correct
99 Correct 1 ms 384 KB Output is correct
100 Correct 1 ms 384 KB Output is correct
101 Correct 1 ms 384 KB Output is correct
102 Correct 1 ms 384 KB Output is correct
103 Correct 1 ms 384 KB Output is correct
104 Correct 48 ms 3196 KB Output is correct
105 Correct 106 ms 6136 KB Output is correct
106 Correct 1 ms 384 KB Output is correct
107 Correct 338 ms 11768 KB Output is correct
108 Correct 308 ms 14516 KB Output is correct
109 Correct 3 ms 512 KB Output is correct
110 Correct 672 ms 20344 KB Output is correct
111 Correct 659 ms 23152 KB Output is correct
112 Correct 3 ms 640 KB Output is correct
113 Correct 879 ms 28868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1092 ms 7184 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 851 ms 26104 KB Output is correct
2 Correct 786 ms 25864 KB Output is correct
3 Correct 432 ms 17016 KB Output is correct
4 Correct 63 ms 4132 KB Output is correct
5 Correct 44 ms 3200 KB Output is correct
6 Correct 112 ms 6160 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 246 ms 11776 KB Output is correct
9 Correct 291 ms 14672 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 539 ms 20472 KB Output is correct
12 Correct 613 ms 23348 KB Output is correct
13 Correct 3 ms 640 KB Output is correct
14 Correct 66 ms 632 KB Output is correct
15 Correct 280 ms 888 KB Output is correct
16 Correct 669 ms 1592 KB Output is correct
17 Correct 53 ms 632 KB Output is correct
18 Correct 222 ms 1024 KB Output is correct
19 Correct 514 ms 1144 KB Output is correct
20 Correct 42 ms 632 KB Output is correct
21 Correct 172 ms 888 KB Output is correct
22 Correct 415 ms 1232 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Incorrect 2 ms 384 KB Output isn't correct
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 851 ms 26104 KB Output is correct
2 Correct 786 ms 25864 KB Output is correct
3 Correct 432 ms 17016 KB Output is correct
4 Correct 63 ms 4132 KB Output is correct
5 Correct 44 ms 3200 KB Output is correct
6 Correct 112 ms 6160 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 246 ms 11776 KB Output is correct
9 Correct 291 ms 14672 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 539 ms 20472 KB Output is correct
12 Correct 613 ms 23348 KB Output is correct
13 Correct 3 ms 640 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 0 ms 256 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 917 ms 26104 KB Output is correct
40 Correct 689 ms 25856 KB Output is correct
41 Correct 443 ms 17272 KB Output is correct
42 Correct 64 ms 4260 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 1 ms 360 KB Output is correct
51 Correct 1 ms 384 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 1 ms 384 KB Output is correct
54 Correct 1 ms 384 KB Output is correct
55 Correct 1 ms 384 KB Output is correct
56 Correct 1 ms 384 KB Output is correct
57 Correct 784 ms 29508 KB Output is correct
58 Correct 740 ms 29544 KB Output is correct
59 Correct 870 ms 29268 KB Output is correct
60 Correct 790 ms 29040 KB Output is correct
61 Correct 840 ms 29048 KB Output is correct
62 Correct 912 ms 29128 KB Output is correct
63 Correct 888 ms 29192 KB Output is correct
64 Correct 895 ms 28972 KB Output is correct
65 Correct 849 ms 28924 KB Output is correct
66 Correct 847 ms 29052 KB Output is correct
67 Correct 805 ms 29144 KB Output is correct
68 Correct 786 ms 29132 KB Output is correct
69 Correct 799 ms 29188 KB Output is correct
70 Correct 751 ms 29112 KB Output is correct
71 Correct 1 ms 384 KB Output is correct
72 Correct 10 ms 1152 KB Output is correct
73 Correct 10 ms 1152 KB Output is correct
74 Correct 10 ms 1152 KB Output is correct
75 Correct 10 ms 1152 KB Output is correct
76 Correct 10 ms 1152 KB Output is correct
77 Correct 12 ms 1196 KB Output is correct
78 Correct 11 ms 1200 KB Output is correct
79 Correct 13 ms 1152 KB Output is correct
80 Correct 851 ms 29116 KB Output is correct
81 Correct 873 ms 29072 KB Output is correct
82 Correct 835 ms 29076 KB Output is correct
83 Correct 846 ms 29120 KB Output is correct
84 Correct 8 ms 1024 KB Output is correct
85 Correct 6 ms 948 KB Output is correct
86 Correct 8 ms 1152 KB Output is correct
87 Correct 9 ms 1056 KB Output is correct
88 Correct 8 ms 1160 KB Output is correct
89 Correct 9 ms 1052 KB Output is correct
90 Correct 9 ms 1144 KB Output is correct
91 Correct 10 ms 1152 KB Output is correct
92 Correct 10 ms 1284 KB Output is correct
93 Correct 9 ms 1152 KB Output is correct
94 Correct 1 ms 384 KB Output is correct
95 Correct 1 ms 384 KB Output is correct
96 Correct 1 ms 384 KB Output is correct
97 Correct 1 ms 384 KB Output is correct
98 Correct 1 ms 384 KB Output is correct
99 Correct 1 ms 384 KB Output is correct
100 Correct 1 ms 384 KB Output is correct
101 Correct 1 ms 384 KB Output is correct
102 Correct 1 ms 384 KB Output is correct
103 Correct 1 ms 384 KB Output is correct
104 Correct 48 ms 3196 KB Output is correct
105 Correct 106 ms 6136 KB Output is correct
106 Correct 1 ms 384 KB Output is correct
107 Correct 338 ms 11768 KB Output is correct
108 Correct 308 ms 14516 KB Output is correct
109 Correct 3 ms 512 KB Output is correct
110 Correct 672 ms 20344 KB Output is correct
111 Correct 659 ms 23152 KB Output is correct
112 Correct 3 ms 640 KB Output is correct
113 Correct 879 ms 28868 KB Output is correct
114 Execution timed out 1092 ms 7184 KB Time limit exceeded
115 Halted 0 ms 0 KB -