답안 #306648

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
306648 2020-09-26T05:01:15 Z tengiz05 꿈 (IOI13_dreaming) C++17
59 / 100
1000 ms 16628 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 1e5+5;
bool used[N];
vector<pair<int, int>> edges[N];
// dfs for calculating maximum depth. (V[i] - distance from the root)
int mx, mxind;
vector<int> vertex;
void dfs(int u, int p, int dist, vector<int> &V, bool flag = 0){
	used[u] = true;
	if(flag)vertex.push_back(u);
	V[u] = dist;
	if(dist > mx){
		mx = dist;
		mxind = u;
	}
	for(auto X : edges[u]){
		int v = X.first;
		int cost = X.second;
		if(v == p)continue;
		dfs(v, u, dist + cost, V, flag);
	}
}

//calculate best center for the tree
int max_diameter;
int calculate_center(int u){
	vertex.clear();
	mx = -1;
	vector<int> no_need(n);
	dfs(u, u, 0, no_need, 1);
	mx = -1;
	int ind1 = mxind;
	vector<int> a(n);
	dfs(ind1, ind1, 0, a);
	
	int ind2 = mxind;
	vector<int> b(n);
	dfs(ind2, ind2, 0, b);
	max_diameter = max(max_diameter, mx);
	int mn = INT_MAX;
	for(auto x : vertex){
		mn = min(mn, max(a[x], b[x]));
	}return mn;
}
int travelTime(int _N, int M, int L, int A[], int B[], int T[]) {
	n = _N;
	for(int i=0;i<M;i++){
		edges[A[i]].push_back({B[i], T[i]});
		edges[B[i]].push_back({A[i], T[i]});
	}
	vector<int> v;
	for(int i=0;i<n;i++){
		if(!used[i]){
			v.push_back(calculate_center(i));
		}
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	if(v.size() == 1){
		return max_diameter;
	}else {
		return max(max(max_diameter, v[0]+v[1]+L), ((v.size() > 2)? v[1]+v[2]+L*2 : 0));
	}
}

/*

12 8 2
0 8 4
8 2 2
2 7 4
5 11 3
5 1 7
1 3 1
1 9 5
10 6 3

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 15348 KB Output is correct
2 Correct 69 ms 15348 KB Output is correct
3 Correct 45 ms 10996 KB Output is correct
4 Correct 10 ms 4480 KB Output is correct
5 Correct 8 ms 3712 KB Output is correct
6 Correct 17 ms 5524 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 32 ms 7072 KB Output is correct
9 Correct 43 ms 8824 KB Output is correct
10 Correct 2 ms 2816 KB Output is correct
11 Correct 77 ms 10616 KB Output is correct
12 Correct 86 ms 12912 KB Output is correct
13 Correct 3 ms 2816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 15348 KB Output is correct
2 Correct 69 ms 15348 KB Output is correct
3 Correct 45 ms 10996 KB Output is correct
4 Correct 10 ms 4480 KB Output is correct
5 Correct 8 ms 3712 KB Output is correct
6 Correct 17 ms 5524 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 32 ms 7072 KB Output is correct
9 Correct 43 ms 8824 KB Output is correct
10 Correct 2 ms 2816 KB Output is correct
11 Correct 77 ms 10616 KB Output is correct
12 Correct 86 ms 12912 KB Output is correct
13 Correct 3 ms 2816 KB Output is correct
14 Correct 2 ms 2688 KB Output is correct
15 Correct 2 ms 2688 KB Output is correct
16 Correct 2 ms 2720 KB Output is correct
17 Correct 2 ms 2688 KB Output is correct
18 Correct 2 ms 2688 KB Output is correct
19 Correct 2 ms 2688 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
21 Correct 2 ms 2688 KB Output is correct
22 Correct 2 ms 2688 KB Output is correct
23 Correct 2 ms 2688 KB Output is correct
24 Correct 2 ms 2688 KB Output is correct
25 Correct 2 ms 2688 KB Output is correct
26 Correct 2 ms 2688 KB Output is correct
27 Correct 2 ms 2688 KB Output is correct
28 Correct 2 ms 2688 KB Output is correct
29 Correct 2 ms 2688 KB Output is correct
30 Correct 2 ms 2688 KB Output is correct
31 Correct 2 ms 2688 KB Output is correct
32 Correct 2 ms 2688 KB Output is correct
33 Correct 2 ms 2688 KB Output is correct
34 Correct 2 ms 2688 KB Output is correct
35 Correct 2 ms 2688 KB Output is correct
36 Correct 2 ms 2688 KB Output is correct
37 Correct 2 ms 2688 KB Output is correct
38 Correct 2 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 15348 KB Output is correct
2 Correct 69 ms 15348 KB Output is correct
3 Correct 45 ms 10996 KB Output is correct
4 Correct 10 ms 4480 KB Output is correct
5 Correct 8 ms 3712 KB Output is correct
6 Correct 17 ms 5524 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 32 ms 7072 KB Output is correct
9 Correct 43 ms 8824 KB Output is correct
10 Correct 2 ms 2816 KB Output is correct
11 Correct 77 ms 10616 KB Output is correct
12 Correct 86 ms 12912 KB Output is correct
13 Correct 3 ms 2816 KB Output is correct
14 Correct 2 ms 2688 KB Output is correct
15 Correct 2 ms 2688 KB Output is correct
16 Correct 2 ms 2720 KB Output is correct
17 Correct 2 ms 2688 KB Output is correct
18 Correct 2 ms 2688 KB Output is correct
19 Correct 2 ms 2688 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
21 Correct 2 ms 2688 KB Output is correct
22 Correct 2 ms 2688 KB Output is correct
23 Correct 2 ms 2688 KB Output is correct
24 Correct 2 ms 2688 KB Output is correct
25 Correct 2 ms 2688 KB Output is correct
26 Correct 2 ms 2688 KB Output is correct
27 Correct 2 ms 2688 KB Output is correct
28 Correct 2 ms 2688 KB Output is correct
29 Correct 2 ms 2688 KB Output is correct
30 Correct 2 ms 2688 KB Output is correct
31 Correct 2 ms 2688 KB Output is correct
32 Correct 2 ms 2688 KB Output is correct
33 Correct 2 ms 2688 KB Output is correct
34 Correct 2 ms 2688 KB Output is correct
35 Correct 2 ms 2688 KB Output is correct
36 Correct 2 ms 2688 KB Output is correct
37 Correct 2 ms 2688 KB Output is correct
38 Correct 2 ms 2688 KB Output is correct
39 Correct 75 ms 15452 KB Output is correct
40 Correct 74 ms 15352 KB Output is correct
41 Correct 47 ms 10996 KB Output is correct
42 Correct 11 ms 4564 KB Output is correct
43 Correct 2 ms 2688 KB Output is correct
44 Correct 2 ms 2688 KB Output is correct
45 Correct 2 ms 2688 KB Output is correct
46 Correct 2 ms 2688 KB Output is correct
47 Correct 2 ms 2688 KB Output is correct
48 Correct 3 ms 2688 KB Output is correct
49 Correct 2 ms 2688 KB Output is correct
50 Correct 2 ms 2688 KB Output is correct
51 Correct 2 ms 2688 KB Output is correct
52 Correct 2 ms 2688 KB Output is correct
53 Correct 2 ms 2688 KB Output is correct
54 Correct 3 ms 2688 KB Output is correct
55 Correct 2 ms 2688 KB Output is correct
56 Correct 2 ms 2688 KB Output is correct
57 Correct 110 ms 9584 KB Output is correct
58 Correct 112 ms 9716 KB Output is correct
59 Correct 110 ms 9584 KB Output is correct
60 Correct 113 ms 9460 KB Output is correct
61 Correct 102 ms 9456 KB Output is correct
62 Correct 108 ms 9252 KB Output is correct
63 Correct 98 ms 9332 KB Output is correct
64 Correct 101 ms 9332 KB Output is correct
65 Correct 102 ms 9332 KB Output is correct
66 Correct 101 ms 9336 KB Output is correct
67 Correct 107 ms 9584 KB Output is correct
68 Correct 114 ms 9584 KB Output is correct
69 Correct 114 ms 9460 KB Output is correct
70 Correct 112 ms 9460 KB Output is correct
71 Correct 3 ms 2816 KB Output is correct
72 Correct 4 ms 2944 KB Output is correct
73 Correct 4 ms 2944 KB Output is correct
74 Correct 4 ms 2944 KB Output is correct
75 Correct 4 ms 2816 KB Output is correct
76 Correct 4 ms 2816 KB Output is correct
77 Correct 4 ms 2944 KB Output is correct
78 Correct 4 ms 2944 KB Output is correct
79 Correct 4 ms 2944 KB Output is correct
80 Correct 110 ms 9308 KB Output is correct
81 Correct 109 ms 9456 KB Output is correct
82 Correct 107 ms 9460 KB Output is correct
83 Correct 104 ms 9456 KB Output is correct
84 Correct 3 ms 2816 KB Output is correct
85 Correct 3 ms 2816 KB Output is correct
86 Correct 3 ms 2816 KB Output is correct
87 Correct 3 ms 2816 KB Output is correct
88 Correct 3 ms 2816 KB Output is correct
89 Correct 3 ms 2816 KB Output is correct
90 Correct 3 ms 2816 KB Output is correct
91 Correct 4 ms 2944 KB Output is correct
92 Correct 4 ms 2816 KB Output is correct
93 Correct 3 ms 2816 KB Output is correct
94 Correct 2 ms 2688 KB Output is correct
95 Correct 2 ms 2688 KB Output is correct
96 Correct 2 ms 2688 KB Output is correct
97 Correct 2 ms 2688 KB Output is correct
98 Correct 2 ms 2688 KB Output is correct
99 Correct 3 ms 2688 KB Output is correct
100 Correct 2 ms 2688 KB Output is correct
101 Correct 2 ms 2688 KB Output is correct
102 Correct 2 ms 2688 KB Output is correct
103 Correct 2 ms 2688 KB Output is correct
104 Correct 9 ms 3712 KB Output is correct
105 Correct 17 ms 5396 KB Output is correct
106 Correct 3 ms 2688 KB Output is correct
107 Correct 31 ms 7064 KB Output is correct
108 Correct 45 ms 8824 KB Output is correct
109 Correct 2 ms 2688 KB Output is correct
110 Correct 75 ms 10616 KB Output is correct
111 Correct 90 ms 13040 KB Output is correct
112 Correct 3 ms 2944 KB Output is correct
113 Correct 133 ms 16628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1083 ms 6920 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 15348 KB Output is correct
2 Correct 69 ms 15348 KB Output is correct
3 Correct 45 ms 10996 KB Output is correct
4 Correct 10 ms 4480 KB Output is correct
5 Correct 8 ms 3712 KB Output is correct
6 Correct 17 ms 5524 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 32 ms 7072 KB Output is correct
9 Correct 43 ms 8824 KB Output is correct
10 Correct 2 ms 2816 KB Output is correct
11 Correct 77 ms 10616 KB Output is correct
12 Correct 86 ms 12912 KB Output is correct
13 Correct 3 ms 2816 KB Output is correct
14 Correct 3 ms 2688 KB Output is correct
15 Correct 4 ms 2816 KB Output is correct
16 Correct 6 ms 2816 KB Output is correct
17 Correct 3 ms 2688 KB Output is correct
18 Correct 4 ms 2816 KB Output is correct
19 Correct 5 ms 2816 KB Output is correct
20 Correct 3 ms 2688 KB Output is correct
21 Correct 4 ms 2816 KB Output is correct
22 Correct 5 ms 2816 KB Output is correct
23 Correct 3 ms 2688 KB Output is correct
24 Correct 2 ms 2688 KB Output is correct
25 Correct 2 ms 2688 KB Output is correct
26 Correct 2 ms 2688 KB Output is correct
27 Correct 2 ms 2688 KB Output is correct
28 Correct 3 ms 2688 KB Output is correct
29 Correct 2 ms 2688 KB Output is correct
30 Correct 2 ms 2688 KB Output is correct
31 Correct 3 ms 2688 KB Output is correct
32 Correct 2 ms 2688 KB Output is correct
33 Correct 3 ms 2688 KB Output is correct
34 Correct 2 ms 2688 KB Output is correct
35 Correct 2 ms 2688 KB Output is correct
36 Correct 2 ms 2688 KB Output is correct
37 Correct 2 ms 2688 KB Output is correct
38 Correct 2 ms 2688 KB Output is correct
39 Correct 3 ms 2688 KB Output is correct
40 Correct 2 ms 2688 KB Output is correct
41 Correct 2 ms 2688 KB Output is correct
42 Correct 4 ms 3072 KB Output is correct
43 Correct 4 ms 3072 KB Output is correct
44 Correct 9 ms 2816 KB Output is correct
45 Correct 13 ms 2816 KB Output is correct
46 Correct 4 ms 2944 KB Output is correct
47 Correct 4 ms 2944 KB Output is correct
48 Correct 11 ms 2816 KB Output is correct
49 Correct 13 ms 2816 KB Output is correct
50 Correct 4 ms 2944 KB Output is correct
51 Correct 4 ms 2944 KB Output is correct
52 Correct 15 ms 2816 KB Output is correct
53 Correct 8 ms 2816 KB Output is correct
54 Correct 4 ms 2944 KB Output is correct
55 Correct 4 ms 2816 KB Output is correct
56 Correct 8 ms 2816 KB Output is correct
57 Correct 8 ms 2816 KB Output is correct
58 Correct 12 ms 2816 KB Output is correct
59 Correct 12 ms 2816 KB Output is correct
60 Correct 4 ms 2944 KB Output is correct
61 Correct 4 ms 2944 KB Output is correct
62 Correct 4 ms 2816 KB Output is correct
63 Correct 5 ms 2816 KB Output is correct
64 Correct 4 ms 2944 KB Output is correct
65 Correct 4 ms 2944 KB Output is correct
66 Correct 12 ms 2816 KB Output is correct
67 Correct 12 ms 2816 KB Output is correct
68 Correct 15 ms 2688 KB Output is correct
69 Correct 16 ms 2688 KB Output is correct
70 Correct 5 ms 2816 KB Output is correct
71 Correct 5 ms 2816 KB Output is correct
72 Correct 11 ms 2816 KB Output is correct
73 Correct 15 ms 2688 KB Output is correct
74 Correct 8 ms 2816 KB Output is correct
75 Correct 5 ms 2816 KB Output is correct
76 Correct 8 ms 2816 KB Output is correct
77 Correct 9 ms 2816 KB Output is correct
78 Correct 11 ms 2816 KB Output is correct
79 Correct 12 ms 2816 KB Output is correct
80 Correct 3 ms 2816 KB Output is correct
81 Correct 3 ms 2816 KB Output is correct
82 Correct 3 ms 2816 KB Output is correct
83 Correct 4 ms 2816 KB Output is correct
84 Correct 3 ms 2816 KB Output is correct
85 Correct 3 ms 2816 KB Output is correct
86 Correct 3 ms 2816 KB Output is correct
87 Correct 4 ms 2816 KB Output is correct
88 Correct 4 ms 2816 KB Output is correct
89 Correct 4 ms 2816 KB Output is correct
90 Correct 3 ms 2688 KB Output is correct
91 Correct 3 ms 2688 KB Output is correct
92 Correct 2 ms 2688 KB Output is correct
93 Correct 2 ms 2688 KB Output is correct
94 Correct 2 ms 2688 KB Output is correct
95 Correct 2 ms 2688 KB Output is correct
96 Correct 2 ms 2688 KB Output is correct
97 Correct 2 ms 2688 KB Output is correct
98 Correct 2 ms 2688 KB Output is correct
99 Correct 2 ms 2688 KB Output is correct
100 Correct 2 ms 2688 KB Output is correct
101 Correct 2 ms 2816 KB Output is correct
102 Correct 3 ms 2816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 15348 KB Output is correct
2 Correct 69 ms 15348 KB Output is correct
3 Correct 45 ms 10996 KB Output is correct
4 Correct 10 ms 4480 KB Output is correct
5 Correct 8 ms 3712 KB Output is correct
6 Correct 17 ms 5524 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 32 ms 7072 KB Output is correct
9 Correct 43 ms 8824 KB Output is correct
10 Correct 2 ms 2816 KB Output is correct
11 Correct 77 ms 10616 KB Output is correct
12 Correct 86 ms 12912 KB Output is correct
13 Correct 3 ms 2816 KB Output is correct
14 Correct 2 ms 2688 KB Output is correct
15 Correct 2 ms 2688 KB Output is correct
16 Correct 2 ms 2720 KB Output is correct
17 Correct 2 ms 2688 KB Output is correct
18 Correct 2 ms 2688 KB Output is correct
19 Correct 2 ms 2688 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
21 Correct 2 ms 2688 KB Output is correct
22 Correct 2 ms 2688 KB Output is correct
23 Correct 2 ms 2688 KB Output is correct
24 Correct 2 ms 2688 KB Output is correct
25 Correct 2 ms 2688 KB Output is correct
26 Correct 2 ms 2688 KB Output is correct
27 Correct 2 ms 2688 KB Output is correct
28 Correct 2 ms 2688 KB Output is correct
29 Correct 2 ms 2688 KB Output is correct
30 Correct 2 ms 2688 KB Output is correct
31 Correct 2 ms 2688 KB Output is correct
32 Correct 2 ms 2688 KB Output is correct
33 Correct 2 ms 2688 KB Output is correct
34 Correct 2 ms 2688 KB Output is correct
35 Correct 2 ms 2688 KB Output is correct
36 Correct 2 ms 2688 KB Output is correct
37 Correct 2 ms 2688 KB Output is correct
38 Correct 2 ms 2688 KB Output is correct
39 Correct 75 ms 15452 KB Output is correct
40 Correct 74 ms 15352 KB Output is correct
41 Correct 47 ms 10996 KB Output is correct
42 Correct 11 ms 4564 KB Output is correct
43 Correct 2 ms 2688 KB Output is correct
44 Correct 2 ms 2688 KB Output is correct
45 Correct 2 ms 2688 KB Output is correct
46 Correct 2 ms 2688 KB Output is correct
47 Correct 2 ms 2688 KB Output is correct
48 Correct 3 ms 2688 KB Output is correct
49 Correct 2 ms 2688 KB Output is correct
50 Correct 2 ms 2688 KB Output is correct
51 Correct 2 ms 2688 KB Output is correct
52 Correct 2 ms 2688 KB Output is correct
53 Correct 2 ms 2688 KB Output is correct
54 Correct 3 ms 2688 KB Output is correct
55 Correct 2 ms 2688 KB Output is correct
56 Correct 2 ms 2688 KB Output is correct
57 Correct 110 ms 9584 KB Output is correct
58 Correct 112 ms 9716 KB Output is correct
59 Correct 110 ms 9584 KB Output is correct
60 Correct 113 ms 9460 KB Output is correct
61 Correct 102 ms 9456 KB Output is correct
62 Correct 108 ms 9252 KB Output is correct
63 Correct 98 ms 9332 KB Output is correct
64 Correct 101 ms 9332 KB Output is correct
65 Correct 102 ms 9332 KB Output is correct
66 Correct 101 ms 9336 KB Output is correct
67 Correct 107 ms 9584 KB Output is correct
68 Correct 114 ms 9584 KB Output is correct
69 Correct 114 ms 9460 KB Output is correct
70 Correct 112 ms 9460 KB Output is correct
71 Correct 3 ms 2816 KB Output is correct
72 Correct 4 ms 2944 KB Output is correct
73 Correct 4 ms 2944 KB Output is correct
74 Correct 4 ms 2944 KB Output is correct
75 Correct 4 ms 2816 KB Output is correct
76 Correct 4 ms 2816 KB Output is correct
77 Correct 4 ms 2944 KB Output is correct
78 Correct 4 ms 2944 KB Output is correct
79 Correct 4 ms 2944 KB Output is correct
80 Correct 110 ms 9308 KB Output is correct
81 Correct 109 ms 9456 KB Output is correct
82 Correct 107 ms 9460 KB Output is correct
83 Correct 104 ms 9456 KB Output is correct
84 Correct 3 ms 2816 KB Output is correct
85 Correct 3 ms 2816 KB Output is correct
86 Correct 3 ms 2816 KB Output is correct
87 Correct 3 ms 2816 KB Output is correct
88 Correct 3 ms 2816 KB Output is correct
89 Correct 3 ms 2816 KB Output is correct
90 Correct 3 ms 2816 KB Output is correct
91 Correct 4 ms 2944 KB Output is correct
92 Correct 4 ms 2816 KB Output is correct
93 Correct 3 ms 2816 KB Output is correct
94 Correct 2 ms 2688 KB Output is correct
95 Correct 2 ms 2688 KB Output is correct
96 Correct 2 ms 2688 KB Output is correct
97 Correct 2 ms 2688 KB Output is correct
98 Correct 2 ms 2688 KB Output is correct
99 Correct 3 ms 2688 KB Output is correct
100 Correct 2 ms 2688 KB Output is correct
101 Correct 2 ms 2688 KB Output is correct
102 Correct 2 ms 2688 KB Output is correct
103 Correct 2 ms 2688 KB Output is correct
104 Correct 9 ms 3712 KB Output is correct
105 Correct 17 ms 5396 KB Output is correct
106 Correct 3 ms 2688 KB Output is correct
107 Correct 31 ms 7064 KB Output is correct
108 Correct 45 ms 8824 KB Output is correct
109 Correct 2 ms 2688 KB Output is correct
110 Correct 75 ms 10616 KB Output is correct
111 Correct 90 ms 13040 KB Output is correct
112 Correct 3 ms 2944 KB Output is correct
113 Correct 133 ms 16628 KB Output is correct
114 Execution timed out 1083 ms 6920 KB Time limit exceeded
115 Halted 0 ms 0 KB -