답안 #337724

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
337724 2020-12-21T12:42:35 Z BlancaHM 꿈 (IOI13_dreaming) C++14
59 / 100
1000 ms 10600 KB
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <algorithm>
#include "dreaming.h"
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

pii calcDist(int i, vvpii & G, vector<bool> & visited, vi & dist1, vi & dist2, vi & dist3) {
	queue<int> Q;
	Q.push(i);
	int u, v, t, maxNode = i;
	vector<int> vertices = {};
	dist1[i] = 0;
	while(!Q.empty()) {
		u = Q.front();
		Q.pop();
		visited[u] = true;
		vertices.push_back(u);
		if (dist1[u] > dist1[maxNode])
			maxNode = u;
		for (auto connection: G[u]) {
			v = connection.first;
			t = connection.second;
			if (dist1[v] > dist1[u]+t) {
				dist1[v] = dist1[u]+t;
				Q.push(v);
			}
		}
	}
	dist2[maxNode] = 0;
	Q.push(maxNode);
	while(!Q.empty()) {
		u = Q.front();
		Q.pop();
		if (dist2[u] > dist2[maxNode])
			maxNode = u;
		for (auto connection: G[u]) {
			v = connection.first;
			t = connection.second;
			if (dist2[v] > dist2[u]+t) {
				dist2[v] = dist2[u]+t;
				Q.push(v);
			}
		}
	}
	int diam = dist2[maxNode];
	dist3[maxNode] = 0;
	Q.push(maxNode);
	while(!Q.empty()) {
		u = Q.front();
		Q.pop();
		for (auto connection: G[u]) {
			v = connection.first;
			t = connection.second;
			if (dist3[v] > dist3[u]+t) {
				dist3[v] = dist3[u]+t;
				Q.push(v);
			}
		}
	}
	int ecc = 1e9;
	for (auto vert: vertices) {
		ecc = min(ecc, max(dist2[vert], dist3[vert]));
	}
	return make_pair(ecc, diam);
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
	vvpii G(N, vpii());
	vector<bool> visited(N, false);
	for (int i = 0; i < M; i++) {
		G[A[i]].push_back(make_pair(B[i], T[i]));
		G[B[i]].push_back(make_pair(A[i], T[i]));
	}
	int CC = 0;
	vi diam = {}, ecc = {}, dist1, dist2, dist3;
	dist1 = dist2 = dist3 = vi(N, 1e9);
	pii curCC;
	for (int i = 0; i < N; i++) {
		if (!visited[i]) {
			curCC = calcDist(i, G, visited, dist1, dist2, dist3);
			ecc.push_back(curCC.first);
			diam.push_back(curCC.second);
			CC++;
		}
	}
	for (int i = 1; i < CC; i++) {
		if (ecc[i] > ecc[0])
			swap(ecc[0], ecc[i]);
	}
	int ans = diam[0];
	for (int i = 1; i < CC; i++) {
		ans = max(ans, diam[i]);
		ans = max(ans, ecc[i]+ecc[0]+L);
		for (int j = i+1; j < CC; j++)
			ans = max(ans, ecc[i]+ecc[j]+2*L);
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 8944 KB Output is correct
2 Correct 55 ms 8812 KB Output is correct
3 Correct 35 ms 6124 KB Output is correct
4 Correct 8 ms 1644 KB Output is correct
5 Correct 6 ms 1260 KB Output is correct
6 Correct 13 ms 2412 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 28 ms 4204 KB Output is correct
9 Correct 36 ms 5356 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 58 ms 7148 KB Output is correct
12 Correct 73 ms 8168 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 8944 KB Output is correct
2 Correct 55 ms 8812 KB Output is correct
3 Correct 35 ms 6124 KB Output is correct
4 Correct 8 ms 1644 KB Output is correct
5 Correct 6 ms 1260 KB Output is correct
6 Correct 13 ms 2412 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 28 ms 4204 KB Output is correct
9 Correct 36 ms 5356 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 58 ms 7148 KB Output is correct
12 Correct 73 ms 8168 KB Output is correct
13 Correct 1 ms 364 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 364 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 56 ms 8944 KB Output is correct
2 Correct 55 ms 8812 KB Output is correct
3 Correct 35 ms 6124 KB Output is correct
4 Correct 8 ms 1644 KB Output is correct
5 Correct 6 ms 1260 KB Output is correct
6 Correct 13 ms 2412 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 28 ms 4204 KB Output is correct
9 Correct 36 ms 5356 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 58 ms 7148 KB Output is correct
12 Correct 73 ms 8168 KB Output is correct
13 Correct 1 ms 364 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 364 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 59 ms 9092 KB Output is correct
40 Correct 55 ms 8940 KB Output is correct
41 Correct 35 ms 6252 KB Output is correct
42 Correct 7 ms 1644 KB Output is correct
43 Correct 1 ms 364 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 104 ms 10600 KB Output is correct
58 Correct 104 ms 10380 KB Output is correct
59 Correct 96 ms 10344 KB Output is correct
60 Correct 102 ms 10280 KB Output is correct
61 Correct 94 ms 10344 KB Output is correct
62 Correct 93 ms 10332 KB Output is correct
63 Correct 86 ms 10276 KB Output is correct
64 Correct 86 ms 10268 KB Output is correct
65 Correct 88 ms 10216 KB Output is correct
66 Correct 88 ms 10272 KB Output is correct
67 Correct 95 ms 10344 KB Output is correct
68 Correct 99 ms 10344 KB Output is correct
69 Correct 97 ms 10180 KB Output is correct
70 Correct 105 ms 10116 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 2 ms 620 KB Output is correct
73 Correct 2 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 620 KB Output is correct
78 Correct 2 ms 620 KB Output is correct
79 Correct 2 ms 620 KB Output is correct
80 Correct 95 ms 10352 KB Output is correct
81 Correct 96 ms 10344 KB Output is correct
82 Correct 90 ms 10344 KB Output is correct
83 Correct 93 ms 10344 KB Output is correct
84 Correct 2 ms 620 KB Output is correct
85 Correct 2 ms 492 KB Output is correct
86 Correct 2 ms 620 KB Output is correct
87 Correct 2 ms 620 KB Output is correct
88 Correct 2 ms 620 KB Output is correct
89 Correct 2 ms 620 KB Output is correct
90 Correct 2 ms 620 KB Output is correct
91 Correct 2 ms 620 KB Output is correct
92 Correct 2 ms 620 KB Output is correct
93 Correct 2 ms 620 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 6 ms 1260 KB Output is correct
105 Correct 13 ms 2412 KB Output is correct
106 Correct 1 ms 364 KB Output is correct
107 Correct 26 ms 4204 KB Output is correct
108 Correct 34 ms 5356 KB Output is correct
109 Correct 1 ms 364 KB Output is correct
110 Correct 61 ms 7148 KB Output is correct
111 Correct 68 ms 8168 KB Output is correct
112 Correct 1 ms 364 KB Output is correct
113 Correct 101 ms 9748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1090 ms 7080 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 8944 KB Output is correct
2 Correct 55 ms 8812 KB Output is correct
3 Correct 35 ms 6124 KB Output is correct
4 Correct 8 ms 1644 KB Output is correct
5 Correct 6 ms 1260 KB Output is correct
6 Correct 13 ms 2412 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 28 ms 4204 KB Output is correct
9 Correct 36 ms 5356 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 58 ms 7148 KB Output is correct
12 Correct 73 ms 8168 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 396 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 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 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 1 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 2 ms 620 KB Output is correct
43 Correct 2 ms 620 KB Output is correct
44 Correct 3 ms 620 KB Output is correct
45 Correct 5 ms 492 KB Output is correct
46 Correct 2 ms 620 KB Output is correct
47 Correct 2 ms 620 KB Output is correct
48 Correct 4 ms 492 KB Output is correct
49 Correct 4 ms 492 KB Output is correct
50 Correct 2 ms 620 KB Output is correct
51 Correct 2 ms 620 KB Output is correct
52 Correct 5 ms 492 KB Output is correct
53 Correct 3 ms 620 KB Output is correct
54 Correct 2 ms 620 KB Output is correct
55 Correct 2 ms 620 KB Output is correct
56 Correct 2 ms 620 KB Output is correct
57 Correct 2 ms 620 KB Output is correct
58 Correct 4 ms 492 KB Output is correct
59 Correct 4 ms 492 KB Output is correct
60 Correct 2 ms 620 KB Output is correct
61 Correct 2 ms 620 KB Output is correct
62 Correct 2 ms 620 KB Output is correct
63 Correct 2 ms 620 KB Output is correct
64 Correct 2 ms 620 KB Output is correct
65 Correct 2 ms 620 KB Output is correct
66 Correct 4 ms 492 KB Output is correct
67 Correct 4 ms 492 KB Output is correct
68 Correct 6 ms 492 KB Output is correct
69 Correct 6 ms 492 KB Output is correct
70 Correct 2 ms 620 KB Output is correct
71 Correct 2 ms 620 KB Output is correct
72 Correct 4 ms 492 KB Output is correct
73 Correct 5 ms 492 KB Output is correct
74 Correct 3 ms 620 KB Output is correct
75 Correct 2 ms 620 KB Output is correct
76 Correct 3 ms 620 KB Output is correct
77 Correct 3 ms 620 KB Output is correct
78 Correct 3 ms 492 KB Output is correct
79 Correct 4 ms 492 KB Output is correct
80 Correct 2 ms 620 KB Output is correct
81 Correct 2 ms 492 KB Output is correct
82 Correct 2 ms 620 KB Output is correct
83 Correct 2 ms 620 KB Output is correct
84 Correct 2 ms 620 KB Output is correct
85 Correct 2 ms 620 KB Output is correct
86 Correct 2 ms 620 KB Output is correct
87 Correct 3 ms 620 KB Output is correct
88 Correct 2 ms 620 KB Output is correct
89 Correct 2 ms 620 KB Output is correct
90 Correct 1 ms 364 KB Output is correct
91 Correct 1 ms 364 KB Output is correct
92 Correct 1 ms 364 KB Output is correct
93 Correct 1 ms 364 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
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 8944 KB Output is correct
2 Correct 55 ms 8812 KB Output is correct
3 Correct 35 ms 6124 KB Output is correct
4 Correct 8 ms 1644 KB Output is correct
5 Correct 6 ms 1260 KB Output is correct
6 Correct 13 ms 2412 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 28 ms 4204 KB Output is correct
9 Correct 36 ms 5356 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 58 ms 7148 KB Output is correct
12 Correct 73 ms 8168 KB Output is correct
13 Correct 1 ms 364 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 364 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 59 ms 9092 KB Output is correct
40 Correct 55 ms 8940 KB Output is correct
41 Correct 35 ms 6252 KB Output is correct
42 Correct 7 ms 1644 KB Output is correct
43 Correct 1 ms 364 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 104 ms 10600 KB Output is correct
58 Correct 104 ms 10380 KB Output is correct
59 Correct 96 ms 10344 KB Output is correct
60 Correct 102 ms 10280 KB Output is correct
61 Correct 94 ms 10344 KB Output is correct
62 Correct 93 ms 10332 KB Output is correct
63 Correct 86 ms 10276 KB Output is correct
64 Correct 86 ms 10268 KB Output is correct
65 Correct 88 ms 10216 KB Output is correct
66 Correct 88 ms 10272 KB Output is correct
67 Correct 95 ms 10344 KB Output is correct
68 Correct 99 ms 10344 KB Output is correct
69 Correct 97 ms 10180 KB Output is correct
70 Correct 105 ms 10116 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 2 ms 620 KB Output is correct
73 Correct 2 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 620 KB Output is correct
78 Correct 2 ms 620 KB Output is correct
79 Correct 2 ms 620 KB Output is correct
80 Correct 95 ms 10352 KB Output is correct
81 Correct 96 ms 10344 KB Output is correct
82 Correct 90 ms 10344 KB Output is correct
83 Correct 93 ms 10344 KB Output is correct
84 Correct 2 ms 620 KB Output is correct
85 Correct 2 ms 492 KB Output is correct
86 Correct 2 ms 620 KB Output is correct
87 Correct 2 ms 620 KB Output is correct
88 Correct 2 ms 620 KB Output is correct
89 Correct 2 ms 620 KB Output is correct
90 Correct 2 ms 620 KB Output is correct
91 Correct 2 ms 620 KB Output is correct
92 Correct 2 ms 620 KB Output is correct
93 Correct 2 ms 620 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 6 ms 1260 KB Output is correct
105 Correct 13 ms 2412 KB Output is correct
106 Correct 1 ms 364 KB Output is correct
107 Correct 26 ms 4204 KB Output is correct
108 Correct 34 ms 5356 KB Output is correct
109 Correct 1 ms 364 KB Output is correct
110 Correct 61 ms 7148 KB Output is correct
111 Correct 68 ms 8168 KB Output is correct
112 Correct 1 ms 364 KB Output is correct
113 Correct 101 ms 9748 KB Output is correct
114 Execution timed out 1090 ms 7080 KB Time limit exceeded
115 Halted 0 ms 0 KB -