Submission #887640

# Submission time Handle Problem Language Result Execution time Memory
887640 2023-12-14T22:16:33 Z TAhmed33 Jail (JOI22_jail) C++
5 / 100
593 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector <int> adj[251];
vector <int> g, e, f;
bool dfs (int pos, int par, int c) {
	if (pos == c) {
		g.push_back(pos);
		return 1;
	}
	bool f2 = 0;
	for (auto j : adj[pos]) {
		if (j == par) continue;
		f2 |= dfs(j, pos, c);
	}
	if (f2) g.push_back(pos);
	return f2;
}
int dp[251][251];
int ans (int p1, int p2) {
	int &ret = dp[p1][p2];
	if (ret != -1) return ret;
	if (p1 == (int)e.size() - 1 && p2 == (int)f.size() - 1) return ret = 1;
	ret = 0;
	if (p1 != (int)e.size() - 1 && e[p1 + 1] != f[p2]) ret |= ans(p1 + 1, p2);
	if (p2 != (int)f.size() - 1 && e[p1] != f[p2 + 1]) ret |= ans(p1, p2 + 1);
	return ret;
}
int main () {
	int t = 1;
	cin >> t;
	while (t--) {
		cin >> n;
		for (int i = 1; i <= n; i++) adj[i].clear();
		for (int i = 1; i < n; i++) {
			int a, b;
			cin >> a >> b;
			adj[a].push_back(b);
			adj[b].push_back(a);
		}
		cin >> m;
		int x, y;
		cin >> x >> y;
		dfs(x, -1, y);
		f = g;
		g.clear();
		cin >> x >> y;
		dfs(x, -1, y);
		e = g;
		g.clear();
		memset(dp, -1, sizeof(dp));
		cout << (ans(0, 0) ? "Yes\n" : "No\n");
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Runtime error 593 ms 1048576 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 3 ms 600 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 3 ms 600 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Incorrect 0 ms 604 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 3 ms 600 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Incorrect 0 ms 604 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 3 ms 600 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Incorrect 0 ms 604 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Incorrect 0 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Runtime error 593 ms 1048576 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -