답안 #250953

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
250953 2020-07-19T16:13:50 Z A02 꿈 (IOI13_dreaming) C++14
47 / 100
430 ms 23800 KB
#include "dreaming.h"
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;

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


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

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

    int longest_distance = 0;
    int endpoint = start;

    while (!to_visit.empty()){

            int 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<int, int> distances;
    map<int, int> parent;
    parent[endpoint] = endpoint;

    to_visit.push(endpoint);

    longest_distance = 0;
    int startpoint = endpoint;

    while (!to_visit.empty()){

            int current = to_visit.front();

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

            to_visit.pop();

            for (int 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;
                }
            }
    }

    int radius = longest_distance;

    int current = startpoint;

    int left_distance = longest_distance;
    int right_distance = 0;

    while (current != endpoint){
        radius = min(radius, max(left_distance, right_distance));

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

    }

    return make_pair(radius, longest_distance);

}

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

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

    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<int> region (N, -1);
    int current_region = 0;
    vector<pair<int, int> > radii;

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

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

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

            while (!to_visit.empty()){

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

                for (int 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<int, int> a1 = radii[radii.size() - 1];
        pair<int, int> a2 = radii[radii.size() - 2];
        radii.pop_back();
        radii.pop_back();

        int r1 = (min(max(a1.first, a2.first + L), max(a2.first, a1.first + L)));
        radii.push_back(make_pair(r1, max(a1.second, max(a2.second, a1.first + a2.first + L))));

    }


    return radii[0].second;

    return 42;
}

Compilation message

dreaming.cpp: In function 'std::pair<int, int> calc_centre(int, std::vector<std::vector<std::pair<int, 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:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int j = 0; j < adjacent[current].size(); j++){
                             ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:118:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (int j = 0; j < adjacent[current].size(); j++){
                                 ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 325 ms 20856 KB Output is correct
2 Correct 344 ms 20988 KB Output is correct
3 Correct 189 ms 13976 KB Output is correct
4 Correct 33 ms 3320 KB Output is correct
5 Correct 24 ms 1920 KB Output is correct
6 Correct 55 ms 4856 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 123 ms 7160 KB Output is correct
9 Correct 162 ms 10232 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 247 ms 13340 KB Output is correct
12 Correct 287 ms 16888 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 325 ms 20856 KB Output is correct
2 Correct 344 ms 20988 KB Output is correct
3 Correct 189 ms 13976 KB Output is correct
4 Correct 33 ms 3320 KB Output is correct
5 Correct 24 ms 1920 KB Output is correct
6 Correct 55 ms 4856 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 123 ms 7160 KB Output is correct
9 Correct 162 ms 10232 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 247 ms 13340 KB Output is correct
12 Correct 287 ms 16888 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 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 0 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
# 결과 실행 시간 메모리 Grader output
1 Correct 325 ms 20856 KB Output is correct
2 Correct 344 ms 20988 KB Output is correct
3 Correct 189 ms 13976 KB Output is correct
4 Correct 33 ms 3320 KB Output is correct
5 Correct 24 ms 1920 KB Output is correct
6 Correct 55 ms 4856 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 123 ms 7160 KB Output is correct
9 Correct 162 ms 10232 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 247 ms 13340 KB Output is correct
12 Correct 287 ms 16888 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 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 0 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 354 ms 20880 KB Output is correct
40 Correct 336 ms 20856 KB Output is correct
41 Correct 198 ms 13944 KB Output is correct
42 Correct 35 ms 3328 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 0 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 0 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 0 ms 384 KB Output is correct
51 Correct 0 ms 384 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 0 ms 384 KB Output is correct
54 Correct 0 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 390 ms 22856 KB Output is correct
58 Correct 372 ms 17428 KB Output is correct
59 Correct 364 ms 21612 KB Output is correct
60 Correct 318 ms 16632 KB Output is correct
61 Correct 358 ms 22008 KB Output is correct
62 Correct 333 ms 18864 KB Output is correct
63 Correct 380 ms 23416 KB Output is correct
64 Correct 384 ms 23544 KB Output is correct
65 Correct 430 ms 23800 KB Output is correct
66 Correct 404 ms 23740 KB Output is correct
67 Correct 389 ms 22008 KB Output is correct
68 Correct 376 ms 21836 KB Output is correct
69 Correct 324 ms 17940 KB Output is correct
70 Correct 339 ms 17912 KB Output is correct
71 Correct 0 ms 384 KB Output is correct
72 Correct 6 ms 768 KB Output is correct
73 Correct 6 ms 896 KB Output is correct
74 Correct 9 ms 1024 KB Output is correct
75 Correct 6 ms 896 KB Output is correct
76 Correct 6 ms 896 KB Output is correct
77 Correct 6 ms 896 KB Output is correct
78 Correct 6 ms 896 KB Output is correct
79 Correct 8 ms 896 KB Output is correct
80 Correct 400 ms 19064 KB Output is correct
81 Correct 363 ms 19064 KB Output is correct
82 Correct 352 ms 22008 KB Output is correct
83 Correct 364 ms 23288 KB Output is correct
84 Correct 4 ms 768 KB Output is correct
85 Correct 4 ms 768 KB Output is correct
86 Correct 5 ms 728 KB Output is correct
87 Correct 6 ms 768 KB Output is correct
88 Correct 5 ms 768 KB Output is correct
89 Correct 5 ms 768 KB Output is correct
90 Correct 5 ms 768 KB Output is correct
91 Correct 7 ms 896 KB Output is correct
92 Correct 5 ms 896 KB Output is correct
93 Correct 5 ms 768 KB Output is correct
94 Correct 0 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 0 ms 384 KB Output is correct
98 Correct 0 ms 384 KB Output is correct
99 Correct 0 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 0 ms 384 KB Output is correct
103 Correct 1 ms 384 KB Output is correct
104 Correct 24 ms 1920 KB Output is correct
105 Correct 56 ms 4856 KB Output is correct
106 Correct 1 ms 384 KB Output is correct
107 Correct 119 ms 7172 KB Output is correct
108 Correct 153 ms 10232 KB Output is correct
109 Correct 2 ms 512 KB Output is correct
110 Correct 244 ms 13176 KB Output is correct
111 Correct 281 ms 16888 KB Output is correct
112 Correct 2 ms 512 KB Output is correct
113 Correct 420 ms 23200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 6272 KB Output is correct
2 Correct 55 ms 6336 KB Output is correct
3 Correct 55 ms 6264 KB Output is correct
4 Incorrect 56 ms 6276 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 325 ms 20856 KB Output is correct
2 Correct 344 ms 20988 KB Output is correct
3 Correct 189 ms 13976 KB Output is correct
4 Correct 33 ms 3320 KB Output is correct
5 Correct 24 ms 1920 KB Output is correct
6 Correct 55 ms 4856 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 123 ms 7160 KB Output is correct
9 Correct 162 ms 10232 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 247 ms 13340 KB Output is correct
12 Correct 287 ms 16888 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 4 ms 640 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 4 ms 640 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 1 ms 384 KB Output isn't correct
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 325 ms 20856 KB Output is correct
2 Correct 344 ms 20988 KB Output is correct
3 Correct 189 ms 13976 KB Output is correct
4 Correct 33 ms 3320 KB Output is correct
5 Correct 24 ms 1920 KB Output is correct
6 Correct 55 ms 4856 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 123 ms 7160 KB Output is correct
9 Correct 162 ms 10232 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 247 ms 13340 KB Output is correct
12 Correct 287 ms 16888 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 0 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 0 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 354 ms 20880 KB Output is correct
40 Correct 336 ms 20856 KB Output is correct
41 Correct 198 ms 13944 KB Output is correct
42 Correct 35 ms 3328 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 0 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 0 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 0 ms 384 KB Output is correct
51 Correct 0 ms 384 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 0 ms 384 KB Output is correct
54 Correct 0 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 390 ms 22856 KB Output is correct
58 Correct 372 ms 17428 KB Output is correct
59 Correct 364 ms 21612 KB Output is correct
60 Correct 318 ms 16632 KB Output is correct
61 Correct 358 ms 22008 KB Output is correct
62 Correct 333 ms 18864 KB Output is correct
63 Correct 380 ms 23416 KB Output is correct
64 Correct 384 ms 23544 KB Output is correct
65 Correct 430 ms 23800 KB Output is correct
66 Correct 404 ms 23740 KB Output is correct
67 Correct 389 ms 22008 KB Output is correct
68 Correct 376 ms 21836 KB Output is correct
69 Correct 324 ms 17940 KB Output is correct
70 Correct 339 ms 17912 KB Output is correct
71 Correct 0 ms 384 KB Output is correct
72 Correct 6 ms 768 KB Output is correct
73 Correct 6 ms 896 KB Output is correct
74 Correct 9 ms 1024 KB Output is correct
75 Correct 6 ms 896 KB Output is correct
76 Correct 6 ms 896 KB Output is correct
77 Correct 6 ms 896 KB Output is correct
78 Correct 6 ms 896 KB Output is correct
79 Correct 8 ms 896 KB Output is correct
80 Correct 400 ms 19064 KB Output is correct
81 Correct 363 ms 19064 KB Output is correct
82 Correct 352 ms 22008 KB Output is correct
83 Correct 364 ms 23288 KB Output is correct
84 Correct 4 ms 768 KB Output is correct
85 Correct 4 ms 768 KB Output is correct
86 Correct 5 ms 728 KB Output is correct
87 Correct 6 ms 768 KB Output is correct
88 Correct 5 ms 768 KB Output is correct
89 Correct 5 ms 768 KB Output is correct
90 Correct 5 ms 768 KB Output is correct
91 Correct 7 ms 896 KB Output is correct
92 Correct 5 ms 896 KB Output is correct
93 Correct 5 ms 768 KB Output is correct
94 Correct 0 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 0 ms 384 KB Output is correct
98 Correct 0 ms 384 KB Output is correct
99 Correct 0 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 0 ms 384 KB Output is correct
103 Correct 1 ms 384 KB Output is correct
104 Correct 24 ms 1920 KB Output is correct
105 Correct 56 ms 4856 KB Output is correct
106 Correct 1 ms 384 KB Output is correct
107 Correct 119 ms 7172 KB Output is correct
108 Correct 153 ms 10232 KB Output is correct
109 Correct 2 ms 512 KB Output is correct
110 Correct 244 ms 13176 KB Output is correct
111 Correct 281 ms 16888 KB Output is correct
112 Correct 2 ms 512 KB Output is correct
113 Correct 420 ms 23200 KB Output is correct
114 Correct 54 ms 6272 KB Output is correct
115 Correct 55 ms 6336 KB Output is correct
116 Correct 55 ms 6264 KB Output is correct
117 Incorrect 56 ms 6276 KB Output isn't correct
118 Halted 0 ms 0 KB -