Submission #994234

# Submission time Handle Problem Language Result Execution time Memory
994234 2024-06-07T09:33:18 Z vjudge1 Jail (JOI22_jail) C++17
21 / 100
5000 ms 5988 KB
#include <iostream>
#include <vector>
using namespace std;

int n, m, sz, c;
bool ans;
vector <vector <int>> g(2e5);
vector <int> to(2e5, 0);
vector <bool> del(2e5);

void reset() {
	ans = true;
	for (int i = 1; i <= n; i++) {
		g[i].clear();
		to[i] = 0;
		del[i] = false;
	}
}

int get_c(int x) {
	if (del[x]) return 0;
	del[x] = true;
	int mx = 0, sum = 1;
	for (int i : g[x]) {

	}
	return sum;
}

void cd(int x) {
	sz = get_c(x);
	get_c(x);
}

bool dfs(int x, int y) {
	if (del[x] || to[x]) return false;
	if (x == y) return true;
	del[x] = true;
	bool ret = false;
	for (int i : g[x]) if (dfs(i, y)) ret = true;
	del[x] = false;
	return ret;
}

bool bt() {
	bool kesz = true;
	for (int i = 1; i <= n; i++) if (to[i] && to[i] != i) kesz = false;
	if (kesz) return true;

	for (int i = 1; i <= n; i++) {
		if (!to[i] || to[i] == i) continue;

		int a = to[i];
		to[i] = 0;
		bool jo = dfs(i, a);
		to[i] = a;
		if (!jo) continue;

		swap(to[i], to[a]);
		if (bt()) return true;
		swap(to[i], to[a]);
	}
	return false;
}

void solve() {
	cin >> n;
	reset();
	int a, b;
	for (int i = 0; i < n - 1; i++) {
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		to[a] = b;
	}
	cout << (bt() ? "Yes\n" : "No\n");
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	cin >> t;
	while (t--) solve();
}

Compilation message

jail.cpp: In function 'int get_c(int)':
jail.cpp:24:11: warning: unused variable 'i' [-Wunused-variable]
   24 |  for (int i : g[x]) {
      |           ^
jail.cpp:23:6: warning: unused variable 'mx' [-Wunused-variable]
   23 |  int mx = 0, sum = 1;
      |      ^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5724 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 2 ms 5724 KB Output is correct
4 Correct 8 ms 5980 KB Output is correct
5 Correct 13 ms 5988 KB Output is correct
6 Correct 3 ms 5980 KB Output is correct
7 Correct 3 ms 5980 KB Output is correct
8 Execution timed out 5051 ms 5980 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5736 KB Output is correct
2 Correct 2 ms 5964 KB Output is correct
3 Correct 2 ms 5980 KB Output is correct
4 Correct 2 ms 5980 KB Output is correct
5 Correct 2 ms 5724 KB Output is correct
6 Correct 2 ms 5980 KB Output is correct
7 Correct 3 ms 5724 KB Output is correct
8 Correct 2 ms 5980 KB Output is correct
9 Correct 2 ms 5976 KB Output is correct
10 Correct 2 ms 5980 KB Output is correct
11 Correct 2 ms 5980 KB Output is correct
12 Correct 2 ms 5980 KB Output is correct
13 Correct 2 ms 5724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5736 KB Output is correct
2 Correct 2 ms 5964 KB Output is correct
3 Correct 2 ms 5980 KB Output is correct
4 Correct 2 ms 5980 KB Output is correct
5 Correct 2 ms 5724 KB Output is correct
6 Correct 2 ms 5980 KB Output is correct
7 Correct 3 ms 5724 KB Output is correct
8 Correct 2 ms 5980 KB Output is correct
9 Correct 2 ms 5976 KB Output is correct
10 Correct 2 ms 5980 KB Output is correct
11 Correct 2 ms 5980 KB Output is correct
12 Correct 2 ms 5980 KB Output is correct
13 Correct 2 ms 5724 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 2 ms 5724 KB Output is correct
16 Correct 4 ms 5980 KB Output is correct
17 Correct 3 ms 5980 KB Output is correct
18 Correct 4 ms 5724 KB Output is correct
19 Correct 2 ms 5724 KB Output is correct
20 Correct 4 ms 5988 KB Output is correct
21 Correct 6 ms 5980 KB Output is correct
22 Correct 3 ms 5980 KB Output is correct
23 Correct 2 ms 5724 KB Output is correct
24 Correct 3 ms 5976 KB Output is correct
25 Correct 9 ms 5980 KB Output is correct
26 Correct 4 ms 5980 KB Output is correct
27 Correct 6 ms 5824 KB Output is correct
28 Correct 3 ms 5972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5736 KB Output is correct
2 Correct 2 ms 5964 KB Output is correct
3 Correct 2 ms 5980 KB Output is correct
4 Correct 2 ms 5980 KB Output is correct
5 Correct 2 ms 5724 KB Output is correct
6 Correct 2 ms 5980 KB Output is correct
7 Correct 3 ms 5724 KB Output is correct
8 Correct 2 ms 5980 KB Output is correct
9 Correct 2 ms 5976 KB Output is correct
10 Correct 2 ms 5980 KB Output is correct
11 Correct 2 ms 5980 KB Output is correct
12 Correct 2 ms 5980 KB Output is correct
13 Correct 2 ms 5724 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 2 ms 5724 KB Output is correct
16 Correct 4 ms 5980 KB Output is correct
17 Correct 3 ms 5980 KB Output is correct
18 Correct 4 ms 5724 KB Output is correct
19 Correct 2 ms 5724 KB Output is correct
20 Correct 4 ms 5988 KB Output is correct
21 Correct 6 ms 5980 KB Output is correct
22 Correct 3 ms 5980 KB Output is correct
23 Correct 2 ms 5724 KB Output is correct
24 Correct 3 ms 5976 KB Output is correct
25 Correct 9 ms 5980 KB Output is correct
26 Correct 4 ms 5980 KB Output is correct
27 Correct 6 ms 5824 KB Output is correct
28 Correct 3 ms 5972 KB Output is correct
29 Execution timed out 5020 ms 5976 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5736 KB Output is correct
2 Correct 2 ms 5964 KB Output is correct
3 Correct 2 ms 5980 KB Output is correct
4 Correct 2 ms 5980 KB Output is correct
5 Correct 2 ms 5724 KB Output is correct
6 Correct 2 ms 5980 KB Output is correct
7 Correct 3 ms 5724 KB Output is correct
8 Correct 2 ms 5980 KB Output is correct
9 Correct 2 ms 5976 KB Output is correct
10 Correct 2 ms 5980 KB Output is correct
11 Correct 2 ms 5980 KB Output is correct
12 Correct 2 ms 5980 KB Output is correct
13 Correct 2 ms 5724 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 2 ms 5724 KB Output is correct
16 Correct 4 ms 5980 KB Output is correct
17 Correct 3 ms 5980 KB Output is correct
18 Correct 4 ms 5724 KB Output is correct
19 Correct 2 ms 5724 KB Output is correct
20 Correct 4 ms 5988 KB Output is correct
21 Correct 6 ms 5980 KB Output is correct
22 Correct 3 ms 5980 KB Output is correct
23 Correct 2 ms 5724 KB Output is correct
24 Correct 3 ms 5976 KB Output is correct
25 Correct 9 ms 5980 KB Output is correct
26 Correct 4 ms 5980 KB Output is correct
27 Correct 6 ms 5824 KB Output is correct
28 Correct 3 ms 5972 KB Output is correct
29 Execution timed out 5020 ms 5976 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5724 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 2 ms 5724 KB Output is correct
4 Correct 2 ms 5724 KB Output is correct
5 Correct 59 ms 5952 KB Output is correct
6 Correct 2 ms 5980 KB Output is correct
7 Correct 4 ms 5724 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 2 ms 5724 KB Output is correct
10 Correct 2 ms 5724 KB Output is correct
11 Correct 4 ms 5972 KB Output is correct
12 Execution timed out 5096 ms 5724 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5724 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 2 ms 5724 KB Output is correct
4 Correct 8 ms 5980 KB Output is correct
5 Correct 13 ms 5988 KB Output is correct
6 Correct 3 ms 5980 KB Output is correct
7 Correct 3 ms 5980 KB Output is correct
8 Execution timed out 5051 ms 5980 KB Time limit exceeded
9 Halted 0 ms 0 KB -