답안 #935992

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
935992 2024-02-29T21:23:34 Z TAhmed33 Jail (JOI22_jail) C++
49 / 100
5000 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 120025;
int n, m;
pair <int, int> a[MAXN];
vector <int> adj[MAXN];
set <int> path[MAXN];
vector <int> comp;
bool flag;
void dfs (int pos, int par, int c) {
	comp.push_back(pos);
	if (pos == a[c].second) {
		flag = 1;
		return;
	}
	for (auto j : adj[pos]) {
		if (j == par) continue;
		dfs(j, pos, c);
		if (flag) return;
	}
	comp.pop_back();
}
int vis[MAXN];
void dfs2 (int pos) {
	vis[pos] = 1;
	comp.push_back(pos);
	for (int i = 1; i <= m; i++) {
		if (i == pos) continue;
		if (path[pos].count(a[i].first)) {
			if (vis[i] == 1) {
				flag = 1;
				return;
			}
			if (vis[i] == 0) {
				dfs2(i);
				if (flag) return;
			}
		}
	}
	for (int i = 1; i <= m; i++) {
		if (i == pos) continue;
		if (path[i].count(a[pos].second)) {
			if (vis[i] == 1) {
				flag = 1;
				return;
			}
			if (vis[i] == 0) {
				dfs2(i);
				if (flag) return;
			}
		}
	}
	if (flag) return;
	vis[pos] = 2;
	comp.pop_back();
}
void solve () {
	cin >> n;
	for (int i = 1; i <= n; i++) adj[i].clear();
	for (int i = 1; i < n; i++) {
		int x, y;
		cin >> x >> y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> a[i].first >> a[i].second; vis[i] = 0;
		path[i].clear(); comp.clear(); flag = 0;
		dfs(a[i].first, -1, i);
		for (auto j : comp) path[i].insert(j);
	}
	flag = 0;
	comp.clear();
	for (int i = 1; i <= n && !flag; i++) {
		if (vis[i] == 0) {
			comp.clear();
			dfs2(i);
		}
	}
	cout << (flag ? "No\n" : "Yes\n");
}
int main () {
	ios::sync_with_stdio(0); cin.tie(0);
	int t = 1; cin >> t;
	while (t--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9048 KB Output is correct
2 Correct 2 ms 9304 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 9 ms 9560 KB Output is correct
5 Correct 19 ms 9820 KB Output is correct
6 Correct 3 ms 9052 KB Output is correct
7 Correct 3 ms 9308 KB Output is correct
8 Correct 10 ms 9836 KB Output is correct
9 Correct 1378 ms 140220 KB Output is correct
10 Runtime error 3344 ms 1048576 KB Execution killed with signal 9
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9048 KB Output is correct
2 Correct 3 ms 9052 KB Output is correct
3 Correct 3 ms 9052 KB Output is correct
4 Correct 3 ms 9052 KB Output is correct
5 Correct 3 ms 9052 KB Output is correct
6 Correct 4 ms 9052 KB Output is correct
7 Correct 2 ms 9052 KB Output is correct
8 Correct 3 ms 9052 KB Output is correct
9 Correct 2 ms 9052 KB Output is correct
10 Correct 2 ms 9052 KB Output is correct
11 Correct 3 ms 9052 KB Output is correct
12 Correct 2 ms 9052 KB Output is correct
13 Correct 3 ms 9060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9048 KB Output is correct
2 Correct 3 ms 9052 KB Output is correct
3 Correct 3 ms 9052 KB Output is correct
4 Correct 3 ms 9052 KB Output is correct
5 Correct 3 ms 9052 KB Output is correct
6 Correct 4 ms 9052 KB Output is correct
7 Correct 2 ms 9052 KB Output is correct
8 Correct 3 ms 9052 KB Output is correct
9 Correct 2 ms 9052 KB Output is correct
10 Correct 2 ms 9052 KB Output is correct
11 Correct 3 ms 9052 KB Output is correct
12 Correct 2 ms 9052 KB Output is correct
13 Correct 3 ms 9060 KB Output is correct
14 Correct 2 ms 9052 KB Output is correct
15 Correct 2 ms 9052 KB Output is correct
16 Correct 3 ms 9308 KB Output is correct
17 Correct 2 ms 9052 KB Output is correct
18 Correct 3 ms 9048 KB Output is correct
19 Correct 2 ms 9052 KB Output is correct
20 Correct 3 ms 9052 KB Output is correct
21 Correct 3 ms 9052 KB Output is correct
22 Correct 3 ms 9048 KB Output is correct
23 Correct 2 ms 9052 KB Output is correct
24 Correct 2 ms 9052 KB Output is correct
25 Correct 3 ms 9052 KB Output is correct
26 Correct 2 ms 9048 KB Output is correct
27 Correct 3 ms 9052 KB Output is correct
28 Correct 2 ms 9052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9048 KB Output is correct
2 Correct 3 ms 9052 KB Output is correct
3 Correct 3 ms 9052 KB Output is correct
4 Correct 3 ms 9052 KB Output is correct
5 Correct 3 ms 9052 KB Output is correct
6 Correct 4 ms 9052 KB Output is correct
7 Correct 2 ms 9052 KB Output is correct
8 Correct 3 ms 9052 KB Output is correct
9 Correct 2 ms 9052 KB Output is correct
10 Correct 2 ms 9052 KB Output is correct
11 Correct 3 ms 9052 KB Output is correct
12 Correct 2 ms 9052 KB Output is correct
13 Correct 3 ms 9060 KB Output is correct
14 Correct 2 ms 9052 KB Output is correct
15 Correct 2 ms 9052 KB Output is correct
16 Correct 3 ms 9308 KB Output is correct
17 Correct 2 ms 9052 KB Output is correct
18 Correct 3 ms 9048 KB Output is correct
19 Correct 2 ms 9052 KB Output is correct
20 Correct 3 ms 9052 KB Output is correct
21 Correct 3 ms 9052 KB Output is correct
22 Correct 3 ms 9048 KB Output is correct
23 Correct 2 ms 9052 KB Output is correct
24 Correct 2 ms 9052 KB Output is correct
25 Correct 3 ms 9052 KB Output is correct
26 Correct 2 ms 9048 KB Output is correct
27 Correct 3 ms 9052 KB Output is correct
28 Correct 2 ms 9052 KB Output is correct
29 Correct 9 ms 9820 KB Output is correct
30 Correct 6 ms 9308 KB Output is correct
31 Correct 6 ms 9308 KB Output is correct
32 Correct 9 ms 9308 KB Output is correct
33 Correct 3 ms 9048 KB Output is correct
34 Correct 6 ms 9308 KB Output is correct
35 Correct 10 ms 9572 KB Output is correct
36 Correct 6 ms 9284 KB Output is correct
37 Correct 8 ms 9304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9048 KB Output is correct
2 Correct 3 ms 9052 KB Output is correct
3 Correct 3 ms 9052 KB Output is correct
4 Correct 3 ms 9052 KB Output is correct
5 Correct 3 ms 9052 KB Output is correct
6 Correct 4 ms 9052 KB Output is correct
7 Correct 2 ms 9052 KB Output is correct
8 Correct 3 ms 9052 KB Output is correct
9 Correct 2 ms 9052 KB Output is correct
10 Correct 2 ms 9052 KB Output is correct
11 Correct 3 ms 9052 KB Output is correct
12 Correct 2 ms 9052 KB Output is correct
13 Correct 3 ms 9060 KB Output is correct
14 Correct 2 ms 9052 KB Output is correct
15 Correct 2 ms 9052 KB Output is correct
16 Correct 3 ms 9308 KB Output is correct
17 Correct 2 ms 9052 KB Output is correct
18 Correct 3 ms 9048 KB Output is correct
19 Correct 2 ms 9052 KB Output is correct
20 Correct 3 ms 9052 KB Output is correct
21 Correct 3 ms 9052 KB Output is correct
22 Correct 3 ms 9048 KB Output is correct
23 Correct 2 ms 9052 KB Output is correct
24 Correct 2 ms 9052 KB Output is correct
25 Correct 3 ms 9052 KB Output is correct
26 Correct 2 ms 9048 KB Output is correct
27 Correct 3 ms 9052 KB Output is correct
28 Correct 2 ms 9052 KB Output is correct
29 Correct 9 ms 9820 KB Output is correct
30 Correct 6 ms 9308 KB Output is correct
31 Correct 6 ms 9308 KB Output is correct
32 Correct 9 ms 9308 KB Output is correct
33 Correct 3 ms 9048 KB Output is correct
34 Correct 6 ms 9308 KB Output is correct
35 Correct 10 ms 9572 KB Output is correct
36 Correct 6 ms 9284 KB Output is correct
37 Correct 8 ms 9304 KB Output is correct
38 Correct 1381 ms 140168 KB Output is correct
39 Runtime error 3289 ms 1048576 KB Execution killed with signal 9
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9052 KB Output is correct
2 Correct 2 ms 9052 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 2 ms 9048 KB Output is correct
5 Correct 7 ms 9308 KB Output is correct
6 Correct 2 ms 9052 KB Output is correct
7 Correct 2 ms 9052 KB Output is correct
8 Correct 2 ms 9052 KB Output is correct
9 Correct 2 ms 9052 KB Output is correct
10 Correct 2 ms 9052 KB Output is correct
11 Correct 2 ms 9052 KB Output is correct
12 Correct 6 ms 9304 KB Output is correct
13 Correct 29 ms 9560 KB Output is correct
14 Correct 56 ms 10064 KB Output is correct
15 Correct 46 ms 9732 KB Output is correct
16 Execution timed out 5073 ms 18172 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9048 KB Output is correct
2 Correct 2 ms 9304 KB Output is correct
3 Correct 2 ms 9052 KB Output is correct
4 Correct 9 ms 9560 KB Output is correct
5 Correct 19 ms 9820 KB Output is correct
6 Correct 3 ms 9052 KB Output is correct
7 Correct 3 ms 9308 KB Output is correct
8 Correct 10 ms 9836 KB Output is correct
9 Correct 1378 ms 140220 KB Output is correct
10 Runtime error 3344 ms 1048576 KB Execution killed with signal 9
11 Halted 0 ms 0 KB -