Submission #990545

# Submission time Handle Problem Language Result Execution time Memory
990545 2024-05-30T15:48:51 Z OAleksa Jail (JOI22_jail) C++14
61 / 100
5000 ms 34864 KB
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
const int N = 120069;
const int K = 20;
int n, m, a[N], b[N];
int tin[N], tout[N], timer, up[N][K], dep[N], is, vis[N];
vector<int> g[N];
vector<int> gg[N];
bool anc(int a, int b) {
	return tin[a] <= tin[b] && tout[a] >= tout[b];
}
int lca(int a, int b) {
	if (anc(a, b))
		return a;
	else if (anc(b, a))
		return b;
	for (int i = K - 1;i >= 0;i--) {
		if (!anc(up[a][i], b) && up[a][i] > 0)
			a = up[a][i];
	}
	return up[a][0];
}
void dfs(int v, int p) {
	up[v][0] = p;
	tin[v] = ++timer;
	for (int i = 1;i < K;i++)
		up[v][i] = up[up[v][i - 1]][i - 1];
	for (auto u : g[v]) {
		if (u == p)
			continue;
		dep[u] = dep[v] + 1;
		dfs(u, v);
	}
	tout[v] = timer;
}
void dfs(int v) {
	if (vis[v]) {
		is += (vis[v] == 1);
		return;
	}
	vis[v] = 1;
	for (auto u : gg[v])
		dfs(u);
	vis[v] = 2;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tt;
	cin >> tt;
	while (tt--) {
		cin >> n;
		timer = is = 0;
		for (int i = 1;i <= n;i++) {
			g[i].clear();
			gg[i].clear();
			vis[i] = 0;
			for (int j = 0;j < K;j++)
				up[i][j] = 0;
		}
		for (int i = 1;i <= n - 1;i++) {
			int a, b;
			cin >> a >> b;
			g[a].push_back(b);
			g[b].push_back(a);
		}
		cin >> m;
		for (int i = 1;i <= m;i++)
			cin >> a[i] >> b[i];
		dep[1] = 0;
		dfs(1, 0);
		for (int i = 1;i <= m;i++) {
			for (int j = 1;j <= m;j++) {
				if (i == j)
					continue;
				// da li je i u j
				//ako b[i] pripada onda j mora zavrsim pre i
				int dis = dep[a[j]] + dep[b[j]] - 2 * dep[lca(a[j], b[j])];
				int dd1 = dep[a[j]] + dep[b[i]] - 2 * dep[lca(a[j], b[i])];
				int dd2 = dep[b[j]] + dep[b[i]] - 2 * dep[lca(b[j], b[i])];
				if (dis == dd1 + dd2) 
					gg[j].push_back(i);
				dd1 = dep[a[j]] + dep[a[i]] - 2 * dep[lca(a[j], a[i])];
				dd2 = dep[b[j]] + dep[a[i]] - 2 * dep[lca(b[j], a[i])];
				if (dis == dd1 + dd2)
					gg[i].push_back(j);
			}
		}
		for (int i = 1;i <= n;i++) {
			if (!vis[i]) {
				dfs(i);
			}
		}
		if (is)
			cout << "No\n";
		else
			cout << "Yes\n";
	}
  return 0; 
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 1 ms 10844 KB Output is correct
3 Correct 1 ms 10844 KB Output is correct
4 Correct 8 ms 10844 KB Output is correct
5 Correct 16 ms 11668 KB Output is correct
6 Correct 2 ms 10844 KB Output is correct
7 Correct 2 ms 10844 KB Output is correct
8 Correct 6 ms 10996 KB Output is correct
9 Correct 97 ms 14416 KB Output is correct
10 Correct 35 ms 31320 KB Output is correct
11 Correct 6 ms 10844 KB Output is correct
12 Correct 66 ms 11924 KB Output is correct
13 Execution timed out 5064 ms 34864 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 1 ms 10844 KB Output is correct
3 Correct 2 ms 10844 KB Output is correct
4 Correct 2 ms 10844 KB Output is correct
5 Correct 2 ms 10844 KB Output is correct
6 Correct 2 ms 10844 KB Output is correct
7 Correct 2 ms 11096 KB Output is correct
8 Correct 2 ms 10852 KB Output is correct
9 Correct 2 ms 10840 KB Output is correct
10 Correct 2 ms 10844 KB Output is correct
11 Correct 2 ms 10844 KB Output is correct
12 Correct 2 ms 10844 KB Output is correct
13 Correct 2 ms 10844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 1 ms 10844 KB Output is correct
3 Correct 2 ms 10844 KB Output is correct
4 Correct 2 ms 10844 KB Output is correct
5 Correct 2 ms 10844 KB Output is correct
6 Correct 2 ms 10844 KB Output is correct
7 Correct 2 ms 11096 KB Output is correct
8 Correct 2 ms 10852 KB Output is correct
9 Correct 2 ms 10840 KB Output is correct
10 Correct 2 ms 10844 KB Output is correct
11 Correct 2 ms 10844 KB Output is correct
12 Correct 2 ms 10844 KB Output is correct
13 Correct 2 ms 10844 KB Output is correct
14 Correct 2 ms 10844 KB Output is correct
15 Correct 2 ms 10844 KB Output is correct
16 Correct 2 ms 10844 KB Output is correct
17 Correct 3 ms 10840 KB Output is correct
18 Correct 2 ms 11096 KB Output is correct
19 Correct 2 ms 10840 KB Output is correct
20 Correct 2 ms 10844 KB Output is correct
21 Correct 3 ms 10844 KB Output is correct
22 Correct 3 ms 10844 KB Output is correct
23 Correct 2 ms 10840 KB Output is correct
24 Correct 2 ms 10844 KB Output is correct
25 Correct 2 ms 10844 KB Output is correct
26 Correct 2 ms 10844 KB Output is correct
27 Correct 3 ms 10844 KB Output is correct
28 Correct 2 ms 10676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 1 ms 10844 KB Output is correct
3 Correct 2 ms 10844 KB Output is correct
4 Correct 2 ms 10844 KB Output is correct
5 Correct 2 ms 10844 KB Output is correct
6 Correct 2 ms 10844 KB Output is correct
7 Correct 2 ms 11096 KB Output is correct
8 Correct 2 ms 10852 KB Output is correct
9 Correct 2 ms 10840 KB Output is correct
10 Correct 2 ms 10844 KB Output is correct
11 Correct 2 ms 10844 KB Output is correct
12 Correct 2 ms 10844 KB Output is correct
13 Correct 2 ms 10844 KB Output is correct
14 Correct 2 ms 10844 KB Output is correct
15 Correct 2 ms 10844 KB Output is correct
16 Correct 2 ms 10844 KB Output is correct
17 Correct 3 ms 10840 KB Output is correct
18 Correct 2 ms 11096 KB Output is correct
19 Correct 2 ms 10840 KB Output is correct
20 Correct 2 ms 10844 KB Output is correct
21 Correct 3 ms 10844 KB Output is correct
22 Correct 3 ms 10844 KB Output is correct
23 Correct 2 ms 10840 KB Output is correct
24 Correct 2 ms 10844 KB Output is correct
25 Correct 2 ms 10844 KB Output is correct
26 Correct 2 ms 10844 KB Output is correct
27 Correct 3 ms 10844 KB Output is correct
28 Correct 2 ms 10676 KB Output is correct
29 Correct 5 ms 10840 KB Output is correct
30 Correct 32 ms 10964 KB Output is correct
31 Correct 21 ms 10844 KB Output is correct
32 Correct 17 ms 10956 KB Output is correct
33 Correct 4 ms 10844 KB Output is correct
34 Correct 58 ms 10968 KB Output is correct
35 Correct 53 ms 10844 KB Output is correct
36 Correct 56 ms 10944 KB Output is correct
37 Correct 33 ms 10844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 1 ms 10844 KB Output is correct
3 Correct 2 ms 10844 KB Output is correct
4 Correct 2 ms 10844 KB Output is correct
5 Correct 2 ms 10844 KB Output is correct
6 Correct 2 ms 10844 KB Output is correct
7 Correct 2 ms 11096 KB Output is correct
8 Correct 2 ms 10852 KB Output is correct
9 Correct 2 ms 10840 KB Output is correct
10 Correct 2 ms 10844 KB Output is correct
11 Correct 2 ms 10844 KB Output is correct
12 Correct 2 ms 10844 KB Output is correct
13 Correct 2 ms 10844 KB Output is correct
14 Correct 2 ms 10844 KB Output is correct
15 Correct 2 ms 10844 KB Output is correct
16 Correct 2 ms 10844 KB Output is correct
17 Correct 3 ms 10840 KB Output is correct
18 Correct 2 ms 11096 KB Output is correct
19 Correct 2 ms 10840 KB Output is correct
20 Correct 2 ms 10844 KB Output is correct
21 Correct 3 ms 10844 KB Output is correct
22 Correct 3 ms 10844 KB Output is correct
23 Correct 2 ms 10840 KB Output is correct
24 Correct 2 ms 10844 KB Output is correct
25 Correct 2 ms 10844 KB Output is correct
26 Correct 2 ms 10844 KB Output is correct
27 Correct 3 ms 10844 KB Output is correct
28 Correct 2 ms 10676 KB Output is correct
29 Correct 5 ms 10840 KB Output is correct
30 Correct 32 ms 10964 KB Output is correct
31 Correct 21 ms 10844 KB Output is correct
32 Correct 17 ms 10956 KB Output is correct
33 Correct 4 ms 10844 KB Output is correct
34 Correct 58 ms 10968 KB Output is correct
35 Correct 53 ms 10844 KB Output is correct
36 Correct 56 ms 10944 KB Output is correct
37 Correct 33 ms 10844 KB Output is correct
38 Correct 103 ms 14420 KB Output is correct
39 Correct 35 ms 31392 KB Output is correct
40 Correct 1691 ms 13536 KB Output is correct
41 Correct 1879 ms 12120 KB Output is correct
42 Correct 1445 ms 13652 KB Output is correct
43 Correct 28 ms 12372 KB Output is correct
44 Correct 1413 ms 11092 KB Output is correct
45 Correct 153 ms 22620 KB Output is correct
46 Correct 144 ms 22608 KB Output is correct
47 Correct 192 ms 26312 KB Output is correct
48 Correct 198 ms 26196 KB Output is correct
49 Correct 186 ms 22864 KB Output is correct
50 Correct 196 ms 22612 KB Output is correct
51 Correct 47 ms 23632 KB Output is correct
52 Correct 45 ms 23632 KB Output is correct
53 Correct 1231 ms 11316 KB Output is correct
54 Correct 129 ms 22364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10840 KB Output is correct
2 Correct 1 ms 10844 KB Output is correct
3 Correct 1 ms 10844 KB Output is correct
4 Correct 1 ms 10844 KB Output is correct
5 Correct 6 ms 10844 KB Output is correct
6 Correct 2 ms 10844 KB Output is correct
7 Correct 2 ms 10904 KB Output is correct
8 Correct 2 ms 10840 KB Output is correct
9 Correct 2 ms 10844 KB Output is correct
10 Correct 2 ms 10844 KB Output is correct
11 Correct 2 ms 10844 KB Output is correct
12 Correct 53 ms 10952 KB Output is correct
13 Correct 626 ms 11348 KB Output is correct
14 Correct 282 ms 11600 KB Output is correct
15 Correct 437 ms 11856 KB Output is correct
16 Execution timed out 5038 ms 22896 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 1 ms 10844 KB Output is correct
3 Correct 1 ms 10844 KB Output is correct
4 Correct 8 ms 10844 KB Output is correct
5 Correct 16 ms 11668 KB Output is correct
6 Correct 2 ms 10844 KB Output is correct
7 Correct 2 ms 10844 KB Output is correct
8 Correct 6 ms 10996 KB Output is correct
9 Correct 97 ms 14416 KB Output is correct
10 Correct 35 ms 31320 KB Output is correct
11 Correct 6 ms 10844 KB Output is correct
12 Correct 66 ms 11924 KB Output is correct
13 Execution timed out 5064 ms 34864 KB Time limit exceeded
14 Halted 0 ms 0 KB -