Submission #986982

# Submission time Handle Problem Language Result Execution time Memory
986982 2024-05-21T16:39:04 Z pedroslrey Keys (IOI21_keys) C++17
37 / 100
3000 ms 27588 KB
#include <bits/stdc++.h>
#include "keys.h"

using namespace std;

vector<int> find_reachable(vector<int> rs, vector<int> us, vector<int> vs, vector<int> cs) {
	int n = rs.size();

	vector<vector<pair<int, int>>> graph(n);
	for (int i = 0; i < us.size(); ++i) {
		graph[us[i]].emplace_back(vs[i], cs[i]);
		graph[vs[i]].emplace_back(us[i], cs[i]);
	}

	function<int (int)> test = [&graph, &rs, n](int s) {
		vector<vector<int>> waiting(n);
		vector<bool> found(n), marc(n);

		queue<int> q;
		q.push(s);

		int sz = 0;
		while (!q.empty()) {
			int u = q.front(); q.pop();

			++sz;
			if (!found[rs[u]]) {
				found[rs[u]] = true;
				for (int x: waiting[rs[u]]) if (!marc[x]) {
					marc[x] = true;
					q.push(x);
				}
			}

			for (auto [v, k]: graph[u]) if (!marc[v])
				if (found[k]) {
					marc[v] = true;
					q.push(v);
				}
				else waiting[k].push_back(v);
		}

		return sz;
	};

	vector<int> best{}; int val = 1e9;
	for (int i = 0; i < n; ++i) {
		int x = test(i);
		
		if (x < val) {
			best = vector<int>{i};
			val = x;
		}
		else if (x == val) best.push_back(i);
	}

	vector<int> ans(n);
	for (int x: best)
		ans[x] = 1;

	return ans;
}

Compilation message

keys.cpp: In function 'std::vector<int> find_reachable(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
keys.cpp:10:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  for (int i = 0; i < us.size(); ++i) {
      |                  ~~^~~~~~~~~~~
keys.cpp: In lambda function:
keys.cpp:35:35: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   35 |    for (auto [v, k]: graph[u]) if (!marc[v])
      |                                   ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 436 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 2 ms 464 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 432 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 436 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 2 ms 464 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 432 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 49 ms 856 KB Output is correct
28 Correct 49 ms 604 KB Output is correct
29 Correct 49 ms 604 KB Output is correct
30 Correct 40 ms 344 KB Output is correct
31 Correct 3 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 2 ms 576 KB Output is correct
34 Correct 11 ms 348 KB Output is correct
35 Correct 18 ms 348 KB Output is correct
36 Correct 77 ms 604 KB Output is correct
37 Correct 56 ms 600 KB Output is correct
38 Correct 80 ms 604 KB Output is correct
39 Correct 67 ms 600 KB Output is correct
40 Correct 6 ms 344 KB Output is correct
41 Correct 28 ms 612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Execution timed out 3019 ms 27588 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 436 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 2 ms 464 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 432 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 49 ms 856 KB Output is correct
28 Correct 49 ms 604 KB Output is correct
29 Correct 49 ms 604 KB Output is correct
30 Correct 40 ms 344 KB Output is correct
31 Correct 3 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 2 ms 576 KB Output is correct
34 Correct 11 ms 348 KB Output is correct
35 Correct 18 ms 348 KB Output is correct
36 Correct 77 ms 604 KB Output is correct
37 Correct 56 ms 600 KB Output is correct
38 Correct 80 ms 604 KB Output is correct
39 Correct 67 ms 600 KB Output is correct
40 Correct 6 ms 344 KB Output is correct
41 Correct 28 ms 612 KB Output is correct
42 Execution timed out 3019 ms 27588 KB Time limit exceeded
43 Halted 0 ms 0 KB -