답안 #335860

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
335860 2020-12-14T07:05:41 Z saarang123 꿈 (IOI13_dreaming) C++14
47 / 100
141 ms 18284 KB
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;

vector<vector<array<int, 2>>> g;
vector<array<int, 2>> cost;
vector<bool> vis;
vector<array<int, 2>> par;

array<int, 2> dfs(int v, int p, int d) {
    vis[v] = true;
    par[v] = {p, d};
    array<int, 2> ret = {d, v};
    for(auto tx : g[v]) {
        int u = tx[0], w = tx[1];
        if(u == p) continue;
        ret = max(ret, dfs(u, v, d + w));
    }
    return ret;
}

int travelTime(int N,int M,int L, int A[],int B[],int T[]) {
    g.resize(N);
    vis.resize(N);
    par.resize(N);
    for(int i = 0; i < M; i++) {
        g[A[i]].push_back({B[i], T[i]});
        g[B[i]].push_back({A[i], T[i]});
    }
    vector<array<int, 2>> diam;
    for(int i = 0; i < N; i++) {
        if(vis[i]) continue;
        array<int, 2> x = dfs(i, -1, 0);
        array<int, 2> d = dfs(x[1], -1, 0);
        array<int, 2> v = {d[1], d[0]};
        while(v[0] != -1) {
            diam.push_back({v[0], par[v[0]][1]});
            v = par[v[0]];
        }
        array<int, 4> ans = {d[0], d[0], 0, d[1]};
        for(auto x : diam) ans = min(ans, {abs(d[0] - 2 * x[1]), d[0] - x[1], x[1], x[0]});
        //cout << ans[1] << ' ' << ans[2] << ' ' << ans[3] << '\n';
        cost.push_back({d[0], ans[3]});
        diam.clear();
    }
    sort(cost.rbegin(), cost.rend());
    for(int i = 1; i < cost.size(); i++) {
        g[cost[0][1]].push_back({cost[i][1], L});
        g[cost[i][1]].push_back({cost[0][1], L});
    }
    array<int, 2> x = dfs(1, -1, 0);
    int answer = dfs(x[1], -1, 0)[0];
    return answer;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:47:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for(int i = 1; i < cost.size(); i++) {
      |                    ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 17644 KB Output is correct
2 Correct 73 ms 17512 KB Output is correct
3 Correct 45 ms 11752 KB Output is correct
4 Correct 9 ms 3052 KB Output is correct
5 Correct 7 ms 1772 KB Output is correct
6 Correct 17 ms 4332 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 37 ms 6380 KB Output is correct
9 Correct 46 ms 8816 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 78 ms 11504 KB Output is correct
12 Correct 104 ms 14692 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 17644 KB Output is correct
2 Correct 73 ms 17512 KB Output is correct
3 Correct 45 ms 11752 KB Output is correct
4 Correct 9 ms 3052 KB Output is correct
5 Correct 7 ms 1772 KB Output is correct
6 Correct 17 ms 4332 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 37 ms 6380 KB Output is correct
9 Correct 46 ms 8816 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 78 ms 11504 KB Output is correct
12 Correct 104 ms 14692 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 17644 KB Output is correct
2 Correct 73 ms 17512 KB Output is correct
3 Correct 45 ms 11752 KB Output is correct
4 Correct 9 ms 3052 KB Output is correct
5 Correct 7 ms 1772 KB Output is correct
6 Correct 17 ms 4332 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 37 ms 6380 KB Output is correct
9 Correct 46 ms 8816 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 78 ms 11504 KB Output is correct
12 Correct 104 ms 14692 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 74 ms 17516 KB Output is correct
40 Correct 72 ms 17512 KB Output is correct
41 Correct 56 ms 11624 KB Output is correct
42 Correct 9 ms 3052 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 364 KB Output is correct
50 Correct 1 ms 364 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 1 ms 364 KB Output is correct
53 Correct 1 ms 364 KB Output is correct
54 Correct 1 ms 364 KB Output is correct
55 Correct 1 ms 364 KB Output is correct
56 Correct 1 ms 364 KB Output is correct
57 Correct 114 ms 8684 KB Output is correct
58 Correct 115 ms 8684 KB Output is correct
59 Correct 113 ms 8812 KB Output is correct
60 Correct 112 ms 8684 KB Output is correct
61 Correct 109 ms 8428 KB Output is correct
62 Correct 104 ms 8428 KB Output is correct
63 Correct 99 ms 8300 KB Output is correct
64 Correct 99 ms 8300 KB Output is correct
65 Correct 99 ms 8300 KB Output is correct
66 Correct 105 ms 8368 KB Output is correct
67 Correct 115 ms 8684 KB Output is correct
68 Correct 110 ms 8828 KB Output is correct
69 Correct 114 ms 8684 KB Output is correct
70 Correct 113 ms 8556 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 2 ms 748 KB Output is correct
73 Correct 3 ms 620 KB Output is correct
74 Correct 2 ms 620 KB Output is correct
75 Correct 2 ms 620 KB Output is correct
76 Correct 2 ms 620 KB Output is correct
77 Correct 2 ms 748 KB Output is correct
78 Correct 2 ms 620 KB Output is correct
79 Correct 2 ms 620 KB Output is correct
80 Correct 115 ms 8556 KB Output is correct
81 Correct 116 ms 8684 KB Output is correct
82 Correct 105 ms 8428 KB Output is correct
83 Correct 105 ms 8428 KB Output is correct
84 Correct 2 ms 492 KB Output is correct
85 Correct 2 ms 492 KB Output is correct
86 Correct 2 ms 492 KB Output is correct
87 Correct 2 ms 504 KB Output is correct
88 Correct 2 ms 492 KB Output is correct
89 Correct 2 ms 492 KB Output is correct
90 Correct 2 ms 492 KB Output is correct
91 Correct 2 ms 620 KB Output is correct
92 Correct 2 ms 492 KB Output is correct
93 Correct 2 ms 492 KB Output is correct
94 Correct 1 ms 364 KB Output is correct
95 Correct 1 ms 364 KB Output is correct
96 Correct 1 ms 364 KB Output is correct
97 Correct 1 ms 364 KB Output is correct
98 Correct 1 ms 364 KB Output is correct
99 Correct 1 ms 364 KB Output is correct
100 Correct 1 ms 364 KB Output is correct
101 Correct 1 ms 364 KB Output is correct
102 Correct 1 ms 364 KB Output is correct
103 Correct 1 ms 364 KB Output is correct
104 Correct 7 ms 1644 KB Output is correct
105 Correct 16 ms 4076 KB Output is correct
106 Correct 1 ms 364 KB Output is correct
107 Correct 34 ms 5996 KB Output is correct
108 Correct 46 ms 8432 KB Output is correct
109 Correct 1 ms 512 KB Output is correct
110 Correct 74 ms 10608 KB Output is correct
111 Correct 99 ms 13924 KB Output is correct
112 Correct 1 ms 492 KB Output is correct
113 Correct 141 ms 18284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 7584 KB Output is correct
2 Correct 46 ms 7568 KB Output is correct
3 Correct 48 ms 7968 KB Output is correct
4 Correct 49 ms 7968 KB Output is correct
5 Correct 47 ms 7972 KB Output is correct
6 Correct 51 ms 9064 KB Output is correct
7 Correct 56 ms 8304 KB Output is correct
8 Correct 47 ms 7856 KB Output is correct
9 Correct 48 ms 7736 KB Output is correct
10 Correct 53 ms 8308 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 28 ms 8160 KB Output is correct
13 Correct 27 ms 8160 KB Output is correct
14 Correct 29 ms 8160 KB Output is correct
15 Correct 29 ms 8160 KB Output is correct
16 Correct 30 ms 8168 KB Output is correct
17 Correct 30 ms 8160 KB Output is correct
18 Correct 28 ms 8160 KB Output is correct
19 Correct 28 ms 8160 KB Output is correct
20 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 17644 KB Output is correct
2 Correct 73 ms 17512 KB Output is correct
3 Correct 45 ms 11752 KB Output is correct
4 Correct 9 ms 3052 KB Output is correct
5 Correct 7 ms 1772 KB Output is correct
6 Correct 17 ms 4332 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 37 ms 6380 KB Output is correct
9 Correct 46 ms 8816 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 78 ms 11504 KB Output is correct
12 Correct 104 ms 14692 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 2 ms 620 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 492 KB Output is correct
22 Correct 2 ms 620 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 39 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
41 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 17644 KB Output is correct
2 Correct 73 ms 17512 KB Output is correct
3 Correct 45 ms 11752 KB Output is correct
4 Correct 9 ms 3052 KB Output is correct
5 Correct 7 ms 1772 KB Output is correct
6 Correct 17 ms 4332 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 37 ms 6380 KB Output is correct
9 Correct 46 ms 8816 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 78 ms 11504 KB Output is correct
12 Correct 104 ms 14692 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 74 ms 17516 KB Output is correct
40 Correct 72 ms 17512 KB Output is correct
41 Correct 56 ms 11624 KB Output is correct
42 Correct 9 ms 3052 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 364 KB Output is correct
50 Correct 1 ms 364 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 1 ms 364 KB Output is correct
53 Correct 1 ms 364 KB Output is correct
54 Correct 1 ms 364 KB Output is correct
55 Correct 1 ms 364 KB Output is correct
56 Correct 1 ms 364 KB Output is correct
57 Correct 114 ms 8684 KB Output is correct
58 Correct 115 ms 8684 KB Output is correct
59 Correct 113 ms 8812 KB Output is correct
60 Correct 112 ms 8684 KB Output is correct
61 Correct 109 ms 8428 KB Output is correct
62 Correct 104 ms 8428 KB Output is correct
63 Correct 99 ms 8300 KB Output is correct
64 Correct 99 ms 8300 KB Output is correct
65 Correct 99 ms 8300 KB Output is correct
66 Correct 105 ms 8368 KB Output is correct
67 Correct 115 ms 8684 KB Output is correct
68 Correct 110 ms 8828 KB Output is correct
69 Correct 114 ms 8684 KB Output is correct
70 Correct 113 ms 8556 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 2 ms 748 KB Output is correct
73 Correct 3 ms 620 KB Output is correct
74 Correct 2 ms 620 KB Output is correct
75 Correct 2 ms 620 KB Output is correct
76 Correct 2 ms 620 KB Output is correct
77 Correct 2 ms 748 KB Output is correct
78 Correct 2 ms 620 KB Output is correct
79 Correct 2 ms 620 KB Output is correct
80 Correct 115 ms 8556 KB Output is correct
81 Correct 116 ms 8684 KB Output is correct
82 Correct 105 ms 8428 KB Output is correct
83 Correct 105 ms 8428 KB Output is correct
84 Correct 2 ms 492 KB Output is correct
85 Correct 2 ms 492 KB Output is correct
86 Correct 2 ms 492 KB Output is correct
87 Correct 2 ms 504 KB Output is correct
88 Correct 2 ms 492 KB Output is correct
89 Correct 2 ms 492 KB Output is correct
90 Correct 2 ms 492 KB Output is correct
91 Correct 2 ms 620 KB Output is correct
92 Correct 2 ms 492 KB Output is correct
93 Correct 2 ms 492 KB Output is correct
94 Correct 1 ms 364 KB Output is correct
95 Correct 1 ms 364 KB Output is correct
96 Correct 1 ms 364 KB Output is correct
97 Correct 1 ms 364 KB Output is correct
98 Correct 1 ms 364 KB Output is correct
99 Correct 1 ms 364 KB Output is correct
100 Correct 1 ms 364 KB Output is correct
101 Correct 1 ms 364 KB Output is correct
102 Correct 1 ms 364 KB Output is correct
103 Correct 1 ms 364 KB Output is correct
104 Correct 7 ms 1644 KB Output is correct
105 Correct 16 ms 4076 KB Output is correct
106 Correct 1 ms 364 KB Output is correct
107 Correct 34 ms 5996 KB Output is correct
108 Correct 46 ms 8432 KB Output is correct
109 Correct 1 ms 512 KB Output is correct
110 Correct 74 ms 10608 KB Output is correct
111 Correct 99 ms 13924 KB Output is correct
112 Correct 1 ms 492 KB Output is correct
113 Correct 141 ms 18284 KB Output is correct
114 Correct 52 ms 7584 KB Output is correct
115 Correct 46 ms 7568 KB Output is correct
116 Correct 48 ms 7968 KB Output is correct
117 Correct 49 ms 7968 KB Output is correct
118 Correct 47 ms 7972 KB Output is correct
119 Correct 51 ms 9064 KB Output is correct
120 Correct 56 ms 8304 KB Output is correct
121 Correct 47 ms 7856 KB Output is correct
122 Correct 48 ms 7736 KB Output is correct
123 Correct 53 ms 8308 KB Output is correct
124 Correct 1 ms 364 KB Output is correct
125 Correct 28 ms 8160 KB Output is correct
126 Correct 27 ms 8160 KB Output is correct
127 Correct 29 ms 8160 KB Output is correct
128 Correct 29 ms 8160 KB Output is correct
129 Correct 30 ms 8168 KB Output is correct
130 Correct 30 ms 8160 KB Output is correct
131 Correct 28 ms 8160 KB Output is correct
132 Correct 28 ms 8160 KB Output is correct
133 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
134 Halted 0 ms 0 KB -