답안 #586749

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
586749 2022-06-30T15:59:37 Z AlperenT 꿈 (IOI13_dreaming) C++17
47 / 100
90 ms 15660 KB
#include <bits/stdc++.h>
#include "dreaming.h"

using namespace std;

const int N = 1e5 + 5, INF = 1e9 + 5;

int n, m, l, maxdia, ans = INF, dist1[N], dist2[N];

vector<pair<int, int>> tree[N];

vector<int> sets, nodes;

bool vis[N];

pair<int, int> dfs(int v, int p){
	nodes.push_back(v);

	pair<int, int> mx = {0, v};

	for(auto e : tree[v]){
		if(e.first != p){
			pair<int, int> emx = dfs(e.first, v);

			mx = max(mx, {emx.first + e.second, emx.second});
		}
	}

	return mx;
}

void dfs2(int v, int p, int d, int* dist){
	dist[v] = d;

	for(auto e : tree[v]){
		if(e.first != p){
			dfs2(e.first, v, d + e.second, dist);
		}
	}
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]){
	n = N, m = M, l = L;

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

	for(int v = 0; v < n; v++){
		nodes.clear();

		if(!vis[v]){
			auto p1 = dfs(v, -1);

			int a = p1.second;

			auto p2 = dfs(a, -1);

			int b = p2.second;

			maxdia = max(maxdia, p2.first);

			auto p3 = dfs(b, -1);

			dfs2(a, -1, 0, dist1);
			dfs2(b, -1, 0, dist2);

			int mx = INF;

			for(auto u : nodes) mx = min(mx, max(dist1[u], dist2[u])), vis[u] = true;

			sets.push_back(mx);
		}
	}

	multiset<int> st;

	for(auto x : sets) st.insert(x);
	
	for(auto x : sets){
		st.erase(st.find(x));

		int curans = 0;

		if(st.size() == 0) curans = INF;
		if(st.size() >= 1) curans = max(curans, x + *prev(st.end()) + l);
		if(st.size() >= 2) curans = max(curans, *prev(st.end()) + *prev(prev(st.end())) + 2 * l);

		ans = min(ans, curans);

		st.insert(x);
	}

    return max(ans, maxdia);
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:64:9: warning: variable 'p3' set but not used [-Wunused-but-set-variable]
   64 |    auto p3 = dfs(b, -1);
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 15660 KB Output is correct
2 Correct 49 ms 14436 KB Output is correct
3 Correct 32 ms 10284 KB Output is correct
4 Correct 9 ms 4436 KB Output is correct
5 Correct 6 ms 3540 KB Output is correct
6 Correct 13 ms 5212 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 24 ms 6868 KB Output is correct
9 Correct 33 ms 8276 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 50 ms 9920 KB Output is correct
12 Correct 81 ms 12060 KB Output is correct
13 Correct 2 ms 2764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 1 ms 2684 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 1 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 3 ms 2644 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 1 ms 2644 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 15660 KB Output is correct
2 Correct 49 ms 14436 KB Output is correct
3 Correct 32 ms 10284 KB Output is correct
4 Correct 9 ms 4436 KB Output is correct
5 Correct 6 ms 3540 KB Output is correct
6 Correct 13 ms 5212 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 24 ms 6868 KB Output is correct
9 Correct 33 ms 8276 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 50 ms 9920 KB Output is correct
12 Correct 81 ms 12060 KB Output is correct
13 Correct 2 ms 2764 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 1 ms 2644 KB Output is correct
19 Correct 1 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 1 ms 2644 KB Output is correct
24 Correct 1 ms 2644 KB Output is correct
25 Correct 1 ms 2684 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 2 ms 2644 KB Output is correct
29 Correct 2 ms 2644 KB Output is correct
30 Correct 1 ms 2644 KB Output is correct
31 Correct 2 ms 2644 KB Output is correct
32 Correct 3 ms 2644 KB Output is correct
33 Correct 1 ms 2644 KB Output is correct
34 Correct 1 ms 2644 KB Output is correct
35 Correct 2 ms 2644 KB Output is correct
36 Correct 2 ms 2644 KB Output is correct
37 Correct 1 ms 2644 KB Output is correct
38 Correct 1 ms 2644 KB Output is correct
39 Correct 47 ms 14388 KB Output is correct
40 Correct 52 ms 14360 KB Output is correct
41 Correct 39 ms 10260 KB Output is correct
42 Correct 9 ms 4444 KB Output is correct
43 Correct 2 ms 2644 KB Output is correct
44 Correct 2 ms 2644 KB Output is correct
45 Correct 2 ms 2644 KB Output is correct
46 Correct 1 ms 2644 KB Output is correct
47 Correct 1 ms 2644 KB Output is correct
48 Correct 1 ms 2644 KB Output is correct
49 Correct 1 ms 2644 KB Output is correct
50 Correct 1 ms 2644 KB Output is correct
51 Correct 2 ms 2644 KB Output is correct
52 Correct 1 ms 2644 KB Output is correct
53 Correct 1 ms 2684 KB Output is correct
54 Correct 1 ms 2644 KB Output is correct
55 Correct 2 ms 2644 KB Output is correct
56 Correct 2 ms 2644 KB Output is correct
57 Correct 73 ms 9988 KB Output is correct
58 Correct 67 ms 9408 KB Output is correct
59 Correct 70 ms 9700 KB Output is correct
60 Correct 66 ms 9296 KB Output is correct
61 Correct 64 ms 9668 KB Output is correct
62 Correct 67 ms 9668 KB Output is correct
63 Correct 60 ms 9600 KB Output is correct
64 Correct 60 ms 9628 KB Output is correct
65 Correct 61 ms 9672 KB Output is correct
66 Correct 63 ms 9596 KB Output is correct
67 Correct 70 ms 9892 KB Output is correct
68 Correct 82 ms 9888 KB Output is correct
69 Correct 78 ms 9716 KB Output is correct
70 Correct 77 ms 9324 KB Output is correct
71 Correct 2 ms 2644 KB Output is correct
72 Correct 3 ms 2900 KB Output is correct
73 Correct 3 ms 2900 KB Output is correct
74 Correct 3 ms 2900 KB Output is correct
75 Correct 3 ms 2900 KB Output is correct
76 Correct 3 ms 2900 KB Output is correct
77 Correct 3 ms 2900 KB Output is correct
78 Correct 3 ms 2900 KB Output is correct
79 Correct 3 ms 2900 KB Output is correct
80 Correct 70 ms 9752 KB Output is correct
81 Correct 82 ms 9536 KB Output is correct
82 Correct 74 ms 9668 KB Output is correct
83 Correct 72 ms 9820 KB Output is correct
84 Correct 2 ms 2772 KB Output is correct
85 Correct 3 ms 2772 KB Output is correct
86 Correct 3 ms 2772 KB Output is correct
87 Correct 3 ms 2772 KB Output is correct
88 Correct 3 ms 2808 KB Output is correct
89 Correct 3 ms 2848 KB Output is correct
90 Correct 3 ms 2772 KB Output is correct
91 Correct 3 ms 2900 KB Output is correct
92 Correct 3 ms 2900 KB Output is correct
93 Correct 3 ms 2772 KB Output is correct
94 Correct 2 ms 2644 KB Output is correct
95 Correct 3 ms 2644 KB Output is correct
96 Correct 2 ms 2644 KB Output is correct
97 Correct 2 ms 2644 KB Output is correct
98 Correct 2 ms 2644 KB Output is correct
99 Correct 1 ms 2644 KB Output is correct
100 Correct 2 ms 2644 KB Output is correct
101 Correct 1 ms 2644 KB Output is correct
102 Correct 1 ms 2644 KB Output is correct
103 Correct 1 ms 2644 KB Output is correct
104 Correct 6 ms 3540 KB Output is correct
105 Correct 13 ms 5208 KB Output is correct
106 Correct 1 ms 2644 KB Output is correct
107 Correct 23 ms 6800 KB Output is correct
108 Correct 34 ms 8252 KB Output is correct
109 Correct 3 ms 2644 KB Output is correct
110 Correct 63 ms 9948 KB Output is correct
111 Correct 82 ms 11988 KB Output is correct
112 Correct 3 ms 2772 KB Output is correct
113 Correct 90 ms 15308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 9396 KB Output is correct
2 Correct 45 ms 9424 KB Output is correct
3 Correct 44 ms 9296 KB Output is correct
4 Correct 48 ms 9416 KB Output is correct
5 Correct 53 ms 9312 KB Output is correct
6 Correct 63 ms 9792 KB Output is correct
7 Correct 47 ms 9704 KB Output is correct
8 Correct 45 ms 9168 KB Output is correct
9 Correct 43 ms 9144 KB Output is correct
10 Correct 46 ms 9564 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 37 ms 8584 KB Output is correct
13 Correct 41 ms 8652 KB Output is correct
14 Correct 35 ms 8516 KB Output is correct
15 Correct 35 ms 8620 KB Output is correct
16 Correct 38 ms 8652 KB Output is correct
17 Correct 42 ms 8624 KB Output is correct
18 Correct 36 ms 8592 KB Output is correct
19 Correct 39 ms 8544 KB Output is correct
20 Incorrect 1 ms 2644 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 1 ms 2684 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 1 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 3 ms 2644 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 1 ms 2644 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 2 ms 2772 KB Output is correct
28 Correct 3 ms 2772 KB Output is correct
29 Correct 2 ms 2736 KB Output is correct
30 Correct 3 ms 2772 KB Output is correct
31 Correct 3 ms 2772 KB Output is correct
32 Correct 2 ms 2644 KB Output is correct
33 Correct 2 ms 2772 KB Output is correct
34 Correct 2 ms 2800 KB Output is correct
35 Correct 1 ms 2644 KB Output is correct
36 Correct 1 ms 2644 KB Output is correct
37 Correct 2 ms 2644 KB Output is correct
38 Correct 1 ms 2644 KB Output is correct
39 Correct 2 ms 2644 KB Output is correct
40 Correct 1 ms 2644 KB Output is correct
41 Correct 1 ms 2644 KB Output is correct
42 Correct 2 ms 2644 KB Output is correct
43 Correct 1 ms 2644 KB Output is correct
44 Correct 2 ms 2644 KB Output is correct
45 Correct 1 ms 2644 KB Output is correct
46 Correct 2 ms 2644 KB Output is correct
47 Correct 1 ms 2644 KB Output is correct
48 Correct 2 ms 2644 KB Output is correct
49 Correct 2 ms 2580 KB Output is correct
50 Correct 1 ms 2644 KB Output is correct
51 Correct 2 ms 2644 KB Output is correct
52 Incorrect 2 ms 2644 KB Output isn't correct
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 15660 KB Output is correct
2 Correct 49 ms 14436 KB Output is correct
3 Correct 32 ms 10284 KB Output is correct
4 Correct 9 ms 4436 KB Output is correct
5 Correct 6 ms 3540 KB Output is correct
6 Correct 13 ms 5212 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 24 ms 6868 KB Output is correct
9 Correct 33 ms 8276 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 50 ms 9920 KB Output is correct
12 Correct 81 ms 12060 KB Output is correct
13 Correct 2 ms 2764 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 1 ms 2644 KB Output is correct
19 Correct 1 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 1 ms 2644 KB Output is correct
24 Correct 1 ms 2644 KB Output is correct
25 Correct 1 ms 2684 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 2 ms 2644 KB Output is correct
29 Correct 2 ms 2644 KB Output is correct
30 Correct 1 ms 2644 KB Output is correct
31 Correct 2 ms 2644 KB Output is correct
32 Correct 3 ms 2644 KB Output is correct
33 Correct 1 ms 2644 KB Output is correct
34 Correct 1 ms 2644 KB Output is correct
35 Correct 2 ms 2644 KB Output is correct
36 Correct 2 ms 2644 KB Output is correct
37 Correct 1 ms 2644 KB Output is correct
38 Correct 1 ms 2644 KB Output is correct
39 Correct 47 ms 14388 KB Output is correct
40 Correct 52 ms 14360 KB Output is correct
41 Correct 39 ms 10260 KB Output is correct
42 Correct 9 ms 4444 KB Output is correct
43 Correct 2 ms 2644 KB Output is correct
44 Correct 2 ms 2644 KB Output is correct
45 Correct 2 ms 2644 KB Output is correct
46 Correct 1 ms 2644 KB Output is correct
47 Correct 1 ms 2644 KB Output is correct
48 Correct 1 ms 2644 KB Output is correct
49 Correct 1 ms 2644 KB Output is correct
50 Correct 1 ms 2644 KB Output is correct
51 Correct 2 ms 2644 KB Output is correct
52 Correct 1 ms 2644 KB Output is correct
53 Correct 1 ms 2684 KB Output is correct
54 Correct 1 ms 2644 KB Output is correct
55 Correct 2 ms 2644 KB Output is correct
56 Correct 2 ms 2644 KB Output is correct
57 Correct 73 ms 9988 KB Output is correct
58 Correct 67 ms 9408 KB Output is correct
59 Correct 70 ms 9700 KB Output is correct
60 Correct 66 ms 9296 KB Output is correct
61 Correct 64 ms 9668 KB Output is correct
62 Correct 67 ms 9668 KB Output is correct
63 Correct 60 ms 9600 KB Output is correct
64 Correct 60 ms 9628 KB Output is correct
65 Correct 61 ms 9672 KB Output is correct
66 Correct 63 ms 9596 KB Output is correct
67 Correct 70 ms 9892 KB Output is correct
68 Correct 82 ms 9888 KB Output is correct
69 Correct 78 ms 9716 KB Output is correct
70 Correct 77 ms 9324 KB Output is correct
71 Correct 2 ms 2644 KB Output is correct
72 Correct 3 ms 2900 KB Output is correct
73 Correct 3 ms 2900 KB Output is correct
74 Correct 3 ms 2900 KB Output is correct
75 Correct 3 ms 2900 KB Output is correct
76 Correct 3 ms 2900 KB Output is correct
77 Correct 3 ms 2900 KB Output is correct
78 Correct 3 ms 2900 KB Output is correct
79 Correct 3 ms 2900 KB Output is correct
80 Correct 70 ms 9752 KB Output is correct
81 Correct 82 ms 9536 KB Output is correct
82 Correct 74 ms 9668 KB Output is correct
83 Correct 72 ms 9820 KB Output is correct
84 Correct 2 ms 2772 KB Output is correct
85 Correct 3 ms 2772 KB Output is correct
86 Correct 3 ms 2772 KB Output is correct
87 Correct 3 ms 2772 KB Output is correct
88 Correct 3 ms 2808 KB Output is correct
89 Correct 3 ms 2848 KB Output is correct
90 Correct 3 ms 2772 KB Output is correct
91 Correct 3 ms 2900 KB Output is correct
92 Correct 3 ms 2900 KB Output is correct
93 Correct 3 ms 2772 KB Output is correct
94 Correct 2 ms 2644 KB Output is correct
95 Correct 3 ms 2644 KB Output is correct
96 Correct 2 ms 2644 KB Output is correct
97 Correct 2 ms 2644 KB Output is correct
98 Correct 2 ms 2644 KB Output is correct
99 Correct 1 ms 2644 KB Output is correct
100 Correct 2 ms 2644 KB Output is correct
101 Correct 1 ms 2644 KB Output is correct
102 Correct 1 ms 2644 KB Output is correct
103 Correct 1 ms 2644 KB Output is correct
104 Correct 6 ms 3540 KB Output is correct
105 Correct 13 ms 5208 KB Output is correct
106 Correct 1 ms 2644 KB Output is correct
107 Correct 23 ms 6800 KB Output is correct
108 Correct 34 ms 8252 KB Output is correct
109 Correct 3 ms 2644 KB Output is correct
110 Correct 63 ms 9948 KB Output is correct
111 Correct 82 ms 11988 KB Output is correct
112 Correct 3 ms 2772 KB Output is correct
113 Correct 90 ms 15308 KB Output is correct
114 Correct 45 ms 9396 KB Output is correct
115 Correct 45 ms 9424 KB Output is correct
116 Correct 44 ms 9296 KB Output is correct
117 Correct 48 ms 9416 KB Output is correct
118 Correct 53 ms 9312 KB Output is correct
119 Correct 63 ms 9792 KB Output is correct
120 Correct 47 ms 9704 KB Output is correct
121 Correct 45 ms 9168 KB Output is correct
122 Correct 43 ms 9144 KB Output is correct
123 Correct 46 ms 9564 KB Output is correct
124 Correct 1 ms 2644 KB Output is correct
125 Correct 37 ms 8584 KB Output is correct
126 Correct 41 ms 8652 KB Output is correct
127 Correct 35 ms 8516 KB Output is correct
128 Correct 35 ms 8620 KB Output is correct
129 Correct 38 ms 8652 KB Output is correct
130 Correct 42 ms 8624 KB Output is correct
131 Correct 36 ms 8592 KB Output is correct
132 Correct 39 ms 8544 KB Output is correct
133 Incorrect 1 ms 2644 KB Output isn't correct
134 Halted 0 ms 0 KB -