답안 #994233

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
994233 2024-06-07T09:32:45 Z zsombor Jail (JOI22_jail) C++17
21 / 100
5000 ms 6232 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;
      |      ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5720 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 2 ms 5720 KB Output is correct
4 Correct 9 ms 5984 KB Output is correct
5 Correct 14 ms 5980 KB Output is correct
6 Correct 2 ms 5924 KB Output is correct
7 Correct 3 ms 5980 KB Output is correct
8 Execution timed out 5047 ms 5720 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5724 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 2 ms 5980 KB Output is correct
4 Correct 4 ms 5980 KB Output is correct
5 Correct 3 ms 5980 KB Output is correct
6 Correct 2 ms 5980 KB Output is correct
7 Correct 4 ms 5980 KB Output is correct
8 Correct 2 ms 5976 KB Output is correct
9 Correct 3 ms 5724 KB Output is correct
10 Correct 2 ms 5976 KB Output is correct
11 Correct 4 ms 5976 KB Output is correct
12 Correct 2 ms 5980 KB Output is correct
13 Correct 2 ms 5980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5724 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 2 ms 5980 KB Output is correct
4 Correct 4 ms 5980 KB Output is correct
5 Correct 3 ms 5980 KB Output is correct
6 Correct 2 ms 5980 KB Output is correct
7 Correct 4 ms 5980 KB Output is correct
8 Correct 2 ms 5976 KB Output is correct
9 Correct 3 ms 5724 KB Output is correct
10 Correct 2 ms 5976 KB Output is correct
11 Correct 4 ms 5976 KB Output is correct
12 Correct 2 ms 5980 KB Output is correct
13 Correct 2 ms 5980 KB Output is correct
14 Correct 1 ms 5724 KB Output is correct
15 Correct 1 ms 5724 KB Output is correct
16 Correct 3 ms 5980 KB Output is correct
17 Correct 3 ms 5724 KB Output is correct
18 Correct 6 ms 5976 KB Output is correct
19 Correct 2 ms 5724 KB Output is correct
20 Correct 3 ms 5980 KB Output is correct
21 Correct 9 ms 5980 KB Output is correct
22 Correct 3 ms 5980 KB Output is correct
23 Correct 1 ms 5724 KB Output is correct
24 Correct 2 ms 5980 KB Output is correct
25 Correct 7 ms 5976 KB Output is correct
26 Correct 3 ms 5724 KB Output is correct
27 Correct 4 ms 5988 KB Output is correct
28 Correct 4 ms 5720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5724 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 2 ms 5980 KB Output is correct
4 Correct 4 ms 5980 KB Output is correct
5 Correct 3 ms 5980 KB Output is correct
6 Correct 2 ms 5980 KB Output is correct
7 Correct 4 ms 5980 KB Output is correct
8 Correct 2 ms 5976 KB Output is correct
9 Correct 3 ms 5724 KB Output is correct
10 Correct 2 ms 5976 KB Output is correct
11 Correct 4 ms 5976 KB Output is correct
12 Correct 2 ms 5980 KB Output is correct
13 Correct 2 ms 5980 KB Output is correct
14 Correct 1 ms 5724 KB Output is correct
15 Correct 1 ms 5724 KB Output is correct
16 Correct 3 ms 5980 KB Output is correct
17 Correct 3 ms 5724 KB Output is correct
18 Correct 6 ms 5976 KB Output is correct
19 Correct 2 ms 5724 KB Output is correct
20 Correct 3 ms 5980 KB Output is correct
21 Correct 9 ms 5980 KB Output is correct
22 Correct 3 ms 5980 KB Output is correct
23 Correct 1 ms 5724 KB Output is correct
24 Correct 2 ms 5980 KB Output is correct
25 Correct 7 ms 5976 KB Output is correct
26 Correct 3 ms 5724 KB Output is correct
27 Correct 4 ms 5988 KB Output is correct
28 Correct 4 ms 5720 KB Output is correct
29 Execution timed out 5070 ms 5980 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5724 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 2 ms 5980 KB Output is correct
4 Correct 4 ms 5980 KB Output is correct
5 Correct 3 ms 5980 KB Output is correct
6 Correct 2 ms 5980 KB Output is correct
7 Correct 4 ms 5980 KB Output is correct
8 Correct 2 ms 5976 KB Output is correct
9 Correct 3 ms 5724 KB Output is correct
10 Correct 2 ms 5976 KB Output is correct
11 Correct 4 ms 5976 KB Output is correct
12 Correct 2 ms 5980 KB Output is correct
13 Correct 2 ms 5980 KB Output is correct
14 Correct 1 ms 5724 KB Output is correct
15 Correct 1 ms 5724 KB Output is correct
16 Correct 3 ms 5980 KB Output is correct
17 Correct 3 ms 5724 KB Output is correct
18 Correct 6 ms 5976 KB Output is correct
19 Correct 2 ms 5724 KB Output is correct
20 Correct 3 ms 5980 KB Output is correct
21 Correct 9 ms 5980 KB Output is correct
22 Correct 3 ms 5980 KB Output is correct
23 Correct 1 ms 5724 KB Output is correct
24 Correct 2 ms 5980 KB Output is correct
25 Correct 7 ms 5976 KB Output is correct
26 Correct 3 ms 5724 KB Output is correct
27 Correct 4 ms 5988 KB Output is correct
28 Correct 4 ms 5720 KB Output is correct
29 Execution timed out 5070 ms 5980 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5724 KB Output is correct
2 Correct 1 ms 5724 KB Output is correct
3 Correct 2 ms 5724 KB Output is correct
4 Correct 3 ms 5724 KB Output is correct
5 Correct 71 ms 5728 KB Output is correct
6 Correct 2 ms 6232 KB Output is correct
7 Correct 2 ms 5724 KB Output is correct
8 Correct 2 ms 5976 KB Output is correct
9 Correct 2 ms 5720 KB Output is correct
10 Correct 2 ms 5724 KB Output is correct
11 Correct 4 ms 5724 KB Output is correct
12 Execution timed out 5100 ms 5724 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5720 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 2 ms 5720 KB Output is correct
4 Correct 9 ms 5984 KB Output is correct
5 Correct 14 ms 5980 KB Output is correct
6 Correct 2 ms 5924 KB Output is correct
7 Correct 3 ms 5980 KB Output is correct
8 Execution timed out 5047 ms 5720 KB Time limit exceeded
9 Halted 0 ms 0 KB -