Submission #337712

# Submission time Handle Problem Language Result Execution time Memory
337712 2020-12-21T12:33:54 Z BlancaHM Dreaming (IOI13_dreaming) C++14
59 / 100
1000 ms 17508 KB
#include <iostream>
#include <vector>
#include <queue>
#include <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) {
	queue<int> Q;
	Q.push(i);
	int u, v, t, maxNode = i;
	vector<int> vertices = {};
	map<int, int> dist1, dist2;
	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.find(v) == dist1.end()) {
				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.find(v) == dist2.end()) {
				dist2[v] = dist2[u]+t;
				Q.push(v);
			}
		}
	}
	int diam = dist2[maxNode];
	dist1.clear();
	dist1[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 (dist1.find(v) == dist1.end()) {
				dist1[v] = dist1[u]+t;
				Q.push(v);
			}
		}
	}
	int ecc = 1e9;
	for (auto vert: vertices) {
		//cout << vert << " " << dist1[vert] << " " << dist2[vert] << "\n";
		ecc = min(ecc, max(dist1[vert], dist2[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 = {};
	pii curCC;
	for (int i = 0; i < N; i++) {
		if (!visited[i]) {
			curCC = calcDist(i, G, visited);
			ecc.push_back(curCC.first);
			diam.push_back(curCC.second);
			CC++;
		}
	}
	int ans = diam[0];
	for (int i = 1; i < CC; i++)
		ans = max(ans, diam[i]);
	sort(ecc.begin(), ecc.end(), greater<int>());
	for (int i = 1; i < CC; i++)
		ans = max(ans, ecc[i]+ecc[0]+L);
	for (int i = 1; i < CC; i++) {
		for (int j = i+1; j < CC; j++)
			ans = max(ans, ecc[i]+ecc[j]+2*L);
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 447 ms 15332 KB Output is correct
2 Correct 452 ms 15332 KB Output is correct
3 Correct 248 ms 10088 KB Output is correct
4 Correct 40 ms 2540 KB Output is correct
5 Correct 27 ms 1516 KB Output is correct
6 Correct 68 ms 3564 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 139 ms 5680 KB Output is correct
9 Correct 193 ms 7528 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 296 ms 9704 KB Output is correct
12 Correct 381 ms 12388 KB Output is correct
13 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 447 ms 15332 KB Output is correct
2 Correct 452 ms 15332 KB Output is correct
3 Correct 248 ms 10088 KB Output is correct
4 Correct 40 ms 2540 KB Output is correct
5 Correct 27 ms 1516 KB Output is correct
6 Correct 68 ms 3564 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 139 ms 5680 KB Output is correct
9 Correct 193 ms 7528 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 296 ms 9704 KB Output is correct
12 Correct 381 ms 12388 KB Output is correct
13 Correct 2 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 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 0 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 512 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
# Verdict Execution time Memory Grader output
1 Correct 447 ms 15332 KB Output is correct
2 Correct 452 ms 15332 KB Output is correct
3 Correct 248 ms 10088 KB Output is correct
4 Correct 40 ms 2540 KB Output is correct
5 Correct 27 ms 1516 KB Output is correct
6 Correct 68 ms 3564 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 139 ms 5680 KB Output is correct
9 Correct 193 ms 7528 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 296 ms 9704 KB Output is correct
12 Correct 381 ms 12388 KB Output is correct
13 Correct 2 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 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 0 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 512 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 458 ms 15460 KB Output is correct
40 Correct 455 ms 15460 KB Output is correct
41 Correct 250 ms 10216 KB Output is correct
42 Correct 40 ms 2668 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 599 ms 17252 KB Output is correct
58 Correct 475 ms 13416 KB Output is correct
59 Correct 538 ms 16356 KB Output is correct
60 Correct 463 ms 12832 KB Output is correct
61 Correct 547 ms 16360 KB Output is correct
62 Correct 478 ms 14172 KB Output is correct
63 Correct 615 ms 17508 KB Output is correct
64 Correct 626 ms 17508 KB Output is correct
65 Correct 624 ms 17508 KB Output is correct
66 Correct 630 ms 17508 KB Output is correct
67 Correct 547 ms 16612 KB Output is correct
68 Correct 536 ms 16356 KB Output is correct
69 Correct 473 ms 13636 KB Output is correct
70 Correct 468 ms 13416 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 7 ms 748 KB Output is correct
73 Correct 8 ms 876 KB Output is correct
74 Correct 8 ms 876 KB Output is correct
75 Correct 7 ms 748 KB Output is correct
76 Correct 7 ms 876 KB Output is correct
77 Correct 7 ms 876 KB Output is correct
78 Correct 8 ms 748 KB Output is correct
79 Correct 8 ms 876 KB Output is correct
80 Correct 485 ms 14448 KB Output is correct
81 Correct 495 ms 14824 KB Output is correct
82 Correct 528 ms 16228 KB Output is correct
83 Correct 587 ms 17508 KB Output is correct
84 Correct 5 ms 620 KB Output is correct
85 Correct 5 ms 620 KB Output is correct
86 Correct 5 ms 620 KB Output is correct
87 Correct 6 ms 620 KB Output is correct
88 Correct 6 ms 620 KB Output is correct
89 Correct 6 ms 620 KB Output is correct
90 Correct 6 ms 620 KB Output is correct
91 Correct 7 ms 876 KB Output is correct
92 Correct 7 ms 748 KB Output is correct
93 Correct 6 ms 748 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 380 KB Output is correct
103 Correct 1 ms 364 KB Output is correct
104 Correct 26 ms 1644 KB Output is correct
105 Correct 68 ms 3692 KB Output is correct
106 Correct 1 ms 364 KB Output is correct
107 Correct 139 ms 5540 KB Output is correct
108 Correct 189 ms 7784 KB Output is correct
109 Correct 2 ms 492 KB Output is correct
110 Correct 284 ms 9832 KB Output is correct
111 Correct 380 ms 12516 KB Output is correct
112 Correct 2 ms 492 KB Output is correct
113 Correct 570 ms 16996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1047 ms 5608 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 447 ms 15332 KB Output is correct
2 Correct 452 ms 15332 KB Output is correct
3 Correct 248 ms 10088 KB Output is correct
4 Correct 40 ms 2540 KB Output is correct
5 Correct 27 ms 1516 KB Output is correct
6 Correct 68 ms 3564 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 139 ms 5680 KB Output is correct
9 Correct 193 ms 7528 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 296 ms 9704 KB Output is correct
12 Correct 381 ms 12388 KB Output is correct
13 Correct 2 ms 492 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 3 ms 492 KB Output is correct
16 Correct 4 ms 620 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 3 ms 492 KB Output is correct
19 Correct 4 ms 620 KB Output is correct
20 Correct 2 ms 364 KB Output is correct
21 Correct 3 ms 492 KB Output is correct
22 Correct 4 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 8 ms 876 KB Output is correct
43 Correct 7 ms 876 KB Output is correct
44 Correct 3 ms 492 KB Output is correct
45 Correct 5 ms 492 KB Output is correct
46 Correct 7 ms 748 KB Output is correct
47 Correct 8 ms 876 KB Output is correct
48 Correct 4 ms 492 KB Output is correct
49 Correct 4 ms 492 KB Output is correct
50 Correct 7 ms 748 KB Output is correct
51 Correct 7 ms 768 KB Output is correct
52 Correct 6 ms 492 KB Output is correct
53 Correct 4 ms 492 KB Output is correct
54 Correct 8 ms 876 KB Output is correct
55 Correct 7 ms 748 KB Output is correct
56 Correct 5 ms 492 KB Output is correct
57 Correct 4 ms 492 KB Output is correct
58 Correct 4 ms 492 KB Output is correct
59 Correct 4 ms 492 KB Output is correct
60 Correct 8 ms 876 KB Output is correct
61 Correct 7 ms 876 KB Output is correct
62 Correct 4 ms 620 KB Output is correct
63 Correct 5 ms 620 KB Output is correct
64 Correct 7 ms 748 KB Output is correct
65 Correct 8 ms 876 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 4 ms 620 KB Output is correct
71 Correct 4 ms 620 KB Output is correct
72 Correct 5 ms 492 KB Output is correct
73 Correct 6 ms 492 KB Output is correct
74 Correct 5 ms 620 KB Output is correct
75 Correct 7 ms 876 KB Output is correct
76 Correct 3 ms 492 KB Output is correct
77 Correct 3 ms 492 KB Output is correct
78 Correct 4 ms 492 KB Output is correct
79 Correct 4 ms 492 KB Output is correct
80 Correct 5 ms 620 KB Output is correct
81 Correct 5 ms 620 KB Output is correct
82 Correct 5 ms 620 KB Output is correct
83 Correct 7 ms 620 KB Output is correct
84 Correct 6 ms 620 KB Output is correct
85 Correct 6 ms 620 KB Output is correct
86 Correct 6 ms 620 KB Output is correct
87 Correct 7 ms 776 KB Output is correct
88 Correct 7 ms 748 KB Output is correct
89 Correct 6 ms 748 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 2 ms 492 KB Output is correct
102 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 447 ms 15332 KB Output is correct
2 Correct 452 ms 15332 KB Output is correct
3 Correct 248 ms 10088 KB Output is correct
4 Correct 40 ms 2540 KB Output is correct
5 Correct 27 ms 1516 KB Output is correct
6 Correct 68 ms 3564 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 139 ms 5680 KB Output is correct
9 Correct 193 ms 7528 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 296 ms 9704 KB Output is correct
12 Correct 381 ms 12388 KB Output is correct
13 Correct 2 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 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 0 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 512 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 458 ms 15460 KB Output is correct
40 Correct 455 ms 15460 KB Output is correct
41 Correct 250 ms 10216 KB Output is correct
42 Correct 40 ms 2668 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 599 ms 17252 KB Output is correct
58 Correct 475 ms 13416 KB Output is correct
59 Correct 538 ms 16356 KB Output is correct
60 Correct 463 ms 12832 KB Output is correct
61 Correct 547 ms 16360 KB Output is correct
62 Correct 478 ms 14172 KB Output is correct
63 Correct 615 ms 17508 KB Output is correct
64 Correct 626 ms 17508 KB Output is correct
65 Correct 624 ms 17508 KB Output is correct
66 Correct 630 ms 17508 KB Output is correct
67 Correct 547 ms 16612 KB Output is correct
68 Correct 536 ms 16356 KB Output is correct
69 Correct 473 ms 13636 KB Output is correct
70 Correct 468 ms 13416 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 7 ms 748 KB Output is correct
73 Correct 8 ms 876 KB Output is correct
74 Correct 8 ms 876 KB Output is correct
75 Correct 7 ms 748 KB Output is correct
76 Correct 7 ms 876 KB Output is correct
77 Correct 7 ms 876 KB Output is correct
78 Correct 8 ms 748 KB Output is correct
79 Correct 8 ms 876 KB Output is correct
80 Correct 485 ms 14448 KB Output is correct
81 Correct 495 ms 14824 KB Output is correct
82 Correct 528 ms 16228 KB Output is correct
83 Correct 587 ms 17508 KB Output is correct
84 Correct 5 ms 620 KB Output is correct
85 Correct 5 ms 620 KB Output is correct
86 Correct 5 ms 620 KB Output is correct
87 Correct 6 ms 620 KB Output is correct
88 Correct 6 ms 620 KB Output is correct
89 Correct 6 ms 620 KB Output is correct
90 Correct 6 ms 620 KB Output is correct
91 Correct 7 ms 876 KB Output is correct
92 Correct 7 ms 748 KB Output is correct
93 Correct 6 ms 748 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 380 KB Output is correct
103 Correct 1 ms 364 KB Output is correct
104 Correct 26 ms 1644 KB Output is correct
105 Correct 68 ms 3692 KB Output is correct
106 Correct 1 ms 364 KB Output is correct
107 Correct 139 ms 5540 KB Output is correct
108 Correct 189 ms 7784 KB Output is correct
109 Correct 2 ms 492 KB Output is correct
110 Correct 284 ms 9832 KB Output is correct
111 Correct 380 ms 12516 KB Output is correct
112 Correct 2 ms 492 KB Output is correct
113 Correct 570 ms 16996 KB Output is correct
114 Execution timed out 1047 ms 5608 KB Time limit exceeded
115 Halted 0 ms 0 KB -