Submission #337714

# Submission time Handle Problem Language Result Execution time Memory
337714 2020-12-21T12:37:47 Z BlancaHM Dreaming (IOI13_dreaming) C++14
59 / 100
1000 ms 17756 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]);
	for (int i = 1; i < CC; i++) {
		if (ecc[i] > ecc[0])
			swap(ecc[0], ecc[i]);
	}
	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 461 ms 15588 KB Output is correct
2 Correct 461 ms 15672 KB Output is correct
3 Correct 251 ms 10344 KB Output is correct
4 Correct 40 ms 2668 KB Output is correct
5 Correct 28 ms 1644 KB Output is correct
6 Correct 68 ms 3820 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 141 ms 5668 KB Output is correct
9 Correct 193 ms 7784 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 284 ms 9960 KB Output is correct
12 Correct 381 ms 12644 KB Output is correct
13 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 461 ms 15588 KB Output is correct
2 Correct 461 ms 15672 KB Output is correct
3 Correct 251 ms 10344 KB Output is correct
4 Correct 40 ms 2668 KB Output is correct
5 Correct 28 ms 1644 KB Output is correct
6 Correct 68 ms 3820 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 141 ms 5668 KB Output is correct
9 Correct 193 ms 7784 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 284 ms 9960 KB Output is correct
12 Correct 381 ms 12644 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 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
# Verdict Execution time Memory Grader output
1 Correct 461 ms 15588 KB Output is correct
2 Correct 461 ms 15672 KB Output is correct
3 Correct 251 ms 10344 KB Output is correct
4 Correct 40 ms 2668 KB Output is correct
5 Correct 28 ms 1644 KB Output is correct
6 Correct 68 ms 3820 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 141 ms 5668 KB Output is correct
9 Correct 193 ms 7784 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 284 ms 9960 KB Output is correct
12 Correct 381 ms 12644 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 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 473 ms 15584 KB Output is correct
40 Correct 458 ms 15588 KB Output is correct
41 Correct 244 ms 10472 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 590 ms 17508 KB Output is correct
58 Correct 475 ms 13544 KB Output is correct
59 Correct 545 ms 16484 KB Output is correct
60 Correct 452 ms 12920 KB Output is correct
61 Correct 559 ms 16484 KB Output is correct
62 Correct 479 ms 14300 KB Output is correct
63 Correct 615 ms 17636 KB Output is correct
64 Correct 626 ms 17756 KB Output is correct
65 Correct 606 ms 17636 KB Output is correct
66 Correct 606 ms 17636 KB Output is correct
67 Correct 559 ms 16740 KB Output is correct
68 Correct 535 ms 16612 KB Output is correct
69 Correct 467 ms 13800 KB Output is correct
70 Correct 462 ms 13544 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 8 ms 876 KB Output is correct
78 Correct 7 ms 748 KB Output is correct
79 Correct 8 ms 876 KB Output is correct
80 Correct 503 ms 14704 KB Output is correct
81 Correct 479 ms 14692 KB Output is correct
82 Correct 535 ms 16384 KB Output is correct
83 Correct 580 ms 17620 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 7 ms 748 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 904 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 26 ms 1644 KB Output is correct
105 Correct 68 ms 3948 KB Output is correct
106 Correct 1 ms 364 KB Output is correct
107 Correct 138 ms 5668 KB Output is correct
108 Correct 199 ms 7784 KB Output is correct
109 Correct 2 ms 492 KB Output is correct
110 Correct 288 ms 9888 KB Output is correct
111 Correct 378 ms 12644 KB Output is correct
112 Correct 3 ms 512 KB Output is correct
113 Correct 568 ms 16996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 ms 5736 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 461 ms 15588 KB Output is correct
2 Correct 461 ms 15672 KB Output is correct
3 Correct 251 ms 10344 KB Output is correct
4 Correct 40 ms 2668 KB Output is correct
5 Correct 28 ms 1644 KB Output is correct
6 Correct 68 ms 3820 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 141 ms 5668 KB Output is correct
9 Correct 193 ms 7784 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 284 ms 9960 KB Output is correct
12 Correct 381 ms 12644 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 5 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 8 ms 876 KB Output is correct
44 Correct 4 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 7 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 9 ms 748 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 4 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 4 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 6 ms 620 KB Output is correct
84 Correct 8 ms 620 KB Output is correct
85 Correct 7 ms 620 KB Output is correct
86 Correct 6 ms 768 KB Output is correct
87 Correct 9 ms 876 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 461 ms 15588 KB Output is correct
2 Correct 461 ms 15672 KB Output is correct
3 Correct 251 ms 10344 KB Output is correct
4 Correct 40 ms 2668 KB Output is correct
5 Correct 28 ms 1644 KB Output is correct
6 Correct 68 ms 3820 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 141 ms 5668 KB Output is correct
9 Correct 193 ms 7784 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 284 ms 9960 KB Output is correct
12 Correct 381 ms 12644 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 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 473 ms 15584 KB Output is correct
40 Correct 458 ms 15588 KB Output is correct
41 Correct 244 ms 10472 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 590 ms 17508 KB Output is correct
58 Correct 475 ms 13544 KB Output is correct
59 Correct 545 ms 16484 KB Output is correct
60 Correct 452 ms 12920 KB Output is correct
61 Correct 559 ms 16484 KB Output is correct
62 Correct 479 ms 14300 KB Output is correct
63 Correct 615 ms 17636 KB Output is correct
64 Correct 626 ms 17756 KB Output is correct
65 Correct 606 ms 17636 KB Output is correct
66 Correct 606 ms 17636 KB Output is correct
67 Correct 559 ms 16740 KB Output is correct
68 Correct 535 ms 16612 KB Output is correct
69 Correct 467 ms 13800 KB Output is correct
70 Correct 462 ms 13544 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 8 ms 876 KB Output is correct
78 Correct 7 ms 748 KB Output is correct
79 Correct 8 ms 876 KB Output is correct
80 Correct 503 ms 14704 KB Output is correct
81 Correct 479 ms 14692 KB Output is correct
82 Correct 535 ms 16384 KB Output is correct
83 Correct 580 ms 17620 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 7 ms 748 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 904 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 26 ms 1644 KB Output is correct
105 Correct 68 ms 3948 KB Output is correct
106 Correct 1 ms 364 KB Output is correct
107 Correct 138 ms 5668 KB Output is correct
108 Correct 199 ms 7784 KB Output is correct
109 Correct 2 ms 492 KB Output is correct
110 Correct 288 ms 9888 KB Output is correct
111 Correct 378 ms 12644 KB Output is correct
112 Correct 3 ms 512 KB Output is correct
113 Correct 568 ms 16996 KB Output is correct
114 Execution timed out 1087 ms 5736 KB Time limit exceeded
115 Halted 0 ms 0 KB -