답안 #935991

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
935991 2024-02-29T21:22:26 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) {
			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 3 ms 9052 KB Output is correct
2 Correct 2 ms 9220 KB Output is correct
3 Correct 3 ms 9052 KB Output is correct
4 Correct 10 ms 9564 KB Output is correct
5 Correct 24 ms 9996 KB Output is correct
6 Correct 4 ms 9052 KB Output is correct
7 Correct 4 ms 9308 KB Output is correct
8 Correct 9 ms 9820 KB Output is correct
9 Correct 1362 ms 140136 KB Output is correct
10 Runtime error 3738 ms 1048576 KB Execution killed with signal 9
11 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 4 ms 9300 KB Output is correct
4 Correct 2 ms 9052 KB Output is correct
5 Correct 3 ms 9176 KB Output is correct
6 Correct 2 ms 9052 KB Output is correct
7 Correct 2 ms 9052 KB Output is correct
8 Correct 4 ms 9052 KB Output is correct
9 Correct 3 ms 9052 KB Output is correct
10 Correct 3 ms 9052 KB Output is correct
11 Correct 2 ms 9052 KB Output is correct
12 Correct 2 ms 9052 KB Output is correct
13 Correct 2 ms 9056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9052 KB Output is correct
2 Correct 2 ms 9052 KB Output is correct
3 Correct 4 ms 9300 KB Output is correct
4 Correct 2 ms 9052 KB Output is correct
5 Correct 3 ms 9176 KB Output is correct
6 Correct 2 ms 9052 KB Output is correct
7 Correct 2 ms 9052 KB Output is correct
8 Correct 4 ms 9052 KB Output is correct
9 Correct 3 ms 9052 KB Output is correct
10 Correct 3 ms 9052 KB Output is correct
11 Correct 2 ms 9052 KB Output is correct
12 Correct 2 ms 9052 KB Output is correct
13 Correct 2 ms 9056 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 4 ms 9308 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 9052 KB Output is correct
23 Correct 2 ms 9052 KB Output is correct
24 Correct 2 ms 9052 KB Output is correct
25 Correct 4 ms 9100 KB Output is correct
26 Correct 2 ms 9052 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 9052 KB Output is correct
2 Correct 2 ms 9052 KB Output is correct
3 Correct 4 ms 9300 KB Output is correct
4 Correct 2 ms 9052 KB Output is correct
5 Correct 3 ms 9176 KB Output is correct
6 Correct 2 ms 9052 KB Output is correct
7 Correct 2 ms 9052 KB Output is correct
8 Correct 4 ms 9052 KB Output is correct
9 Correct 3 ms 9052 KB Output is correct
10 Correct 3 ms 9052 KB Output is correct
11 Correct 2 ms 9052 KB Output is correct
12 Correct 2 ms 9052 KB Output is correct
13 Correct 2 ms 9056 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 4 ms 9308 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 9052 KB Output is correct
23 Correct 2 ms 9052 KB Output is correct
24 Correct 2 ms 9052 KB Output is correct
25 Correct 4 ms 9100 KB Output is correct
26 Correct 2 ms 9052 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 5 ms 9320 KB Output is correct
31 Correct 9 ms 9308 KB Output is correct
32 Correct 7 ms 9308 KB Output is correct
33 Correct 3 ms 9052 KB Output is correct
34 Correct 6 ms 9308 KB Output is correct
35 Correct 10 ms 9564 KB Output is correct
36 Correct 6 ms 9308 KB Output is correct
37 Correct 7 ms 9084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9052 KB Output is correct
2 Correct 2 ms 9052 KB Output is correct
3 Correct 4 ms 9300 KB Output is correct
4 Correct 2 ms 9052 KB Output is correct
5 Correct 3 ms 9176 KB Output is correct
6 Correct 2 ms 9052 KB Output is correct
7 Correct 2 ms 9052 KB Output is correct
8 Correct 4 ms 9052 KB Output is correct
9 Correct 3 ms 9052 KB Output is correct
10 Correct 3 ms 9052 KB Output is correct
11 Correct 2 ms 9052 KB Output is correct
12 Correct 2 ms 9052 KB Output is correct
13 Correct 2 ms 9056 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 4 ms 9308 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 9052 KB Output is correct
23 Correct 2 ms 9052 KB Output is correct
24 Correct 2 ms 9052 KB Output is correct
25 Correct 4 ms 9100 KB Output is correct
26 Correct 2 ms 9052 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 5 ms 9320 KB Output is correct
31 Correct 9 ms 9308 KB Output is correct
32 Correct 7 ms 9308 KB Output is correct
33 Correct 3 ms 9052 KB Output is correct
34 Correct 6 ms 9308 KB Output is correct
35 Correct 10 ms 9564 KB Output is correct
36 Correct 6 ms 9308 KB Output is correct
37 Correct 7 ms 9084 KB Output is correct
38 Correct 1488 ms 140220 KB Output is correct
39 Runtime error 3522 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 9052 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 9184 KB Output is correct
12 Correct 9 ms 9288 KB Output is correct
13 Correct 30 ms 9568 KB Output is correct
14 Correct 55 ms 10068 KB Output is correct
15 Correct 46 ms 9816 KB Output is correct
16 Execution timed out 5094 ms 18120 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9052 KB Output is correct
2 Correct 2 ms 9220 KB Output is correct
3 Correct 3 ms 9052 KB Output is correct
4 Correct 10 ms 9564 KB Output is correct
5 Correct 24 ms 9996 KB Output is correct
6 Correct 4 ms 9052 KB Output is correct
7 Correct 4 ms 9308 KB Output is correct
8 Correct 9 ms 9820 KB Output is correct
9 Correct 1362 ms 140136 KB Output is correct
10 Runtime error 3738 ms 1048576 KB Execution killed with signal 9
11 Halted 0 ms 0 KB -