Submission #421698

# Submission time Handle Problem Language Result Execution time Memory
421698 2021-06-09T11:03:57 Z SuhaibSawalha1 Dreaming (IOI13_dreaming) C++17
14 / 100
92 ms 11300 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;

vector<vector<array<int, 2>>> adj;
vector<int> dist, nodes;
int n;

array<int, 2> bfs (int u, int f) {
	if (f == 2) {
		dist.assign(n, 0);
	}
	queue<array<int, 3>> q {{{u, 0}}};
	array<int, 2> MX {0, u};
	int v = 0;
	while (q.size()) {
		++v;
		u = q.front()[0];
		int d = q.front()[1];
		int p = q.front()[2];
		q.pop();
		if (f) {
			nodes.push_back(u);
			dist[u] = max(dist[u], d);
		}
		MX = max(MX, {d, u});
		for (auto &v : adj[u]) {
			if (v[0] != p) {
				q.push({v[0], d + v[1], u});
			}
		}
	}
	return MX;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
	n = N;
	adj.resize(N);
	dist.resize(N);
	for (int i = 0; i < M; ++i) {
		adj[A[i]].push_back({B[i], T[i]});
		adj[B[i]].push_back({A[i], T[i]});
	}
	vector<array<int, 2>> cmp;
	for (int i = 0; i < N; ++i) {
		if (!dist[i]) {
			int a = bfs(i, 0)[1];
			nodes.clear();
			bfs(bfs(a, 1)[1], 1);
			array<int, 2> mn = {(int)2e9, (int)2e9};
			for (int u : nodes) {
				mn = min(mn, {dist[u], u});
			}
			cmp.push_back(mn);
		}
	}
	int mx = (*max_element(cmp.begin(), cmp.end()))[1];
	for (auto &e : cmp) {
		if (e[1] != mx) {
			adj[e[1]].push_back({mx, L});
			adj[mx].push_back({e[1], L});
		}
	}
	return bfs(bfs(0, 2)[1], 2)[0];
}
# Verdict Execution time Memory Grader output
1 Correct 56 ms 7828 KB Output is correct
2 Correct 58 ms 7832 KB Output is correct
3 Correct 36 ms 5136 KB Output is correct
4 Correct 8 ms 1484 KB Output is correct
5 Correct 6 ms 1228 KB Output is correct
6 Correct 14 ms 1996 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 31 ms 3728 KB Output is correct
9 Correct 36 ms 4396 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 57 ms 6364 KB Output is correct
12 Correct 68 ms 7032 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Incorrect 1 ms 204 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 7828 KB Output is correct
2 Correct 58 ms 7832 KB Output is correct
3 Correct 36 ms 5136 KB Output is correct
4 Correct 8 ms 1484 KB Output is correct
5 Correct 6 ms 1228 KB Output is correct
6 Correct 14 ms 1996 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 31 ms 3728 KB Output is correct
9 Correct 36 ms 4396 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 57 ms 6364 KB Output is correct
12 Correct 68 ms 7032 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Incorrect 1 ms 204 KB Output isn't correct
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 74 ms 10920 KB Output is correct
2 Correct 78 ms 9032 KB Output is correct
3 Correct 68 ms 9104 KB Output is correct
4 Correct 68 ms 9084 KB Output is correct
5 Correct 60 ms 9068 KB Output is correct
6 Correct 67 ms 9832 KB Output is correct
7 Correct 76 ms 11300 KB Output is correct
8 Correct 85 ms 10772 KB Output is correct
9 Correct 66 ms 8812 KB Output is correct
10 Correct 92 ms 9268 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 61 ms 10396 KB Output is correct
13 Correct 59 ms 10468 KB Output is correct
14 Correct 59 ms 10396 KB Output is correct
15 Correct 59 ms 10464 KB Output is correct
16 Correct 77 ms 10468 KB Output is correct
17 Correct 61 ms 10420 KB Output is correct
18 Correct 69 ms 10684 KB Output is correct
19 Correct 64 ms 10432 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Incorrect 0 ms 204 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Incorrect 1 ms 204 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 7828 KB Output is correct
2 Correct 58 ms 7832 KB Output is correct
3 Correct 36 ms 5136 KB Output is correct
4 Correct 8 ms 1484 KB Output is correct
5 Correct 6 ms 1228 KB Output is correct
6 Correct 14 ms 1996 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 31 ms 3728 KB Output is correct
9 Correct 36 ms 4396 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 57 ms 6364 KB Output is correct
12 Correct 68 ms 7032 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Incorrect 1 ms 204 KB Output isn't correct
29 Halted 0 ms 0 KB -