답안 #548710

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
548710 2022-04-14T10:23:55 Z nonsensenonsense1 Jail (JOI22_jail) C++17
61 / 100
5000 ms 28872 KB
#include <cstdio>
#include <cstring>
#include <vector>

const int N = 120000;
const int LG = 17;
int n, q, m, s[N], t[N], l[N], in[N], out[N], f[LG][N], u[N];
std::vector<int> g[N];

void dfs(int v) {
	static int dt = 0;
	in[v] = dt++;
	for (int i = 0; i < (int)g[v].size(); ++i) if (g[v][i] != f[0][v]) {
		f[0][g[v][i]] = v;
		dfs(g[v][i]);
	}
	out[v] = dt;
}

bool par(int u, int v) {
	return in[u] <= in[v] && out[u] >= out[v];
}

int lca(int u, int v) {
	if (par(u, v)) return u;
	for (int i = LG - 1; i >= 0; --i) if (!par(f[i][u], v)) u = f[i][u];
	return f[0][u];
}

bool on(int x, int i) {
	return x == l[i] || (par(x, s[i]) != par(x, t[i]));
}

bool dfs1(int v) {
	u[v] = 1;
	for (int i = 0; i < (int)g[v].size(); ++i) 
		if (u[g[v][i]] == 1 || !u[g[v][i]] && !dfs1(g[v][i])) return 0;
	u[v] = 2;
	return 1;
}

int main() {
	scanf("%d", &q);
	while (q--) {
		scanf("%d", &n);
		for (int i = 0; i < n; ++i) g[i].clear();
		for (int i = 1; i < n; ++i) {
			int a, b;
			scanf("%d%d", &a, &b);
			--a;
			--b;
			g[a].push_back(b);
			g[b].push_back(a);
		}
		dfs(0);
		for (int j = 1; j < LG; ++j) for (int i = 0; i < n; ++i) f[j][i] = f[j - 1][f[j - 1][i]];
		scanf("%d", &m);
		for (int i = 0; i < m; ++i) {
			scanf("%d%d", s + i, t + i);
			--s[i];
			--t[i];
			l[i] = lca(s[i], t[i]);
		}
		for (int i = 0; i < m; ++i) g[i].clear();
		for (int i = 0; i < m; ++i) for (int j = 0; j < m; ++j) if (i != j && (on(t[i], j) || on(s[j], i))) g[i].push_back(j);
		memset(u, 0, m << 2);
		bool ok = 1;
		for (int i = 0; i < m; ++i) if (!u[i] && !dfs1(i)) ok = 0;
		printf("%s\n", ok ? "Yes" : "No");
	}
	return 0;
}

Compilation message

jail.cpp: In function 'bool dfs1(int)':
jail.cpp:37:38: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   37 |   if (u[g[v][i]] == 1 || !u[g[v][i]] && !dfs1(g[v][i])) return 0;
      |                          ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
jail.cpp: In function 'int main()':
jail.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |  scanf("%d", &q);
      |  ~~~~~^~~~~~~~~~
jail.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
jail.cpp:49:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |    scanf("%d%d", &a, &b);
      |    ~~~~~^~~~~~~~~~~~~~~~
jail.cpp:57:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |   scanf("%d", &m);
      |   ~~~~~^~~~~~~~~~
jail.cpp:59:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |    scanf("%d%d", s + i, t + i);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3156 KB Output is correct
2 Correct 2 ms 3156 KB Output is correct
3 Correct 2 ms 3156 KB Output is correct
4 Correct 12 ms 3376 KB Output is correct
5 Correct 22 ms 3260 KB Output is correct
6 Correct 3 ms 3284 KB Output is correct
7 Correct 3 ms 3264 KB Output is correct
8 Correct 7 ms 3284 KB Output is correct
9 Correct 70 ms 6268 KB Output is correct
10 Correct 48 ms 24496 KB Output is correct
11 Correct 7 ms 3284 KB Output is correct
12 Correct 55 ms 4252 KB Output is correct
13 Execution timed out 5041 ms 28872 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3156 KB Output is correct
2 Correct 2 ms 3156 KB Output is correct
3 Correct 3 ms 3256 KB Output is correct
4 Correct 3 ms 3248 KB Output is correct
5 Correct 3 ms 3252 KB Output is correct
6 Correct 3 ms 3284 KB Output is correct
7 Correct 3 ms 3252 KB Output is correct
8 Correct 2 ms 3284 KB Output is correct
9 Correct 3 ms 3156 KB Output is correct
10 Correct 3 ms 3284 KB Output is correct
11 Correct 3 ms 3156 KB Output is correct
12 Correct 3 ms 3156 KB Output is correct
13 Correct 2 ms 3156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3156 KB Output is correct
2 Correct 2 ms 3156 KB Output is correct
3 Correct 3 ms 3256 KB Output is correct
4 Correct 3 ms 3248 KB Output is correct
5 Correct 3 ms 3252 KB Output is correct
6 Correct 3 ms 3284 KB Output is correct
7 Correct 3 ms 3252 KB Output is correct
8 Correct 2 ms 3284 KB Output is correct
9 Correct 3 ms 3156 KB Output is correct
10 Correct 3 ms 3284 KB Output is correct
11 Correct 3 ms 3156 KB Output is correct
12 Correct 3 ms 3156 KB Output is correct
13 Correct 2 ms 3156 KB Output is correct
14 Correct 3 ms 3156 KB Output is correct
15 Correct 2 ms 3116 KB Output is correct
16 Correct 4 ms 3284 KB Output is correct
17 Correct 3 ms 3156 KB Output is correct
18 Correct 3 ms 3328 KB Output is correct
19 Correct 2 ms 3156 KB Output is correct
20 Correct 3 ms 3156 KB Output is correct
21 Correct 3 ms 3284 KB Output is correct
22 Correct 3 ms 3284 KB Output is correct
23 Correct 3 ms 3156 KB Output is correct
24 Correct 2 ms 3156 KB Output is correct
25 Correct 3 ms 3244 KB Output is correct
26 Correct 2 ms 3156 KB Output is correct
27 Correct 3 ms 3156 KB Output is correct
28 Correct 3 ms 3156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3156 KB Output is correct
2 Correct 2 ms 3156 KB Output is correct
3 Correct 3 ms 3256 KB Output is correct
4 Correct 3 ms 3248 KB Output is correct
5 Correct 3 ms 3252 KB Output is correct
6 Correct 3 ms 3284 KB Output is correct
7 Correct 3 ms 3252 KB Output is correct
8 Correct 2 ms 3284 KB Output is correct
9 Correct 3 ms 3156 KB Output is correct
10 Correct 3 ms 3284 KB Output is correct
11 Correct 3 ms 3156 KB Output is correct
12 Correct 3 ms 3156 KB Output is correct
13 Correct 2 ms 3156 KB Output is correct
14 Correct 3 ms 3156 KB Output is correct
15 Correct 2 ms 3116 KB Output is correct
16 Correct 4 ms 3284 KB Output is correct
17 Correct 3 ms 3156 KB Output is correct
18 Correct 3 ms 3328 KB Output is correct
19 Correct 2 ms 3156 KB Output is correct
20 Correct 3 ms 3156 KB Output is correct
21 Correct 3 ms 3284 KB Output is correct
22 Correct 3 ms 3284 KB Output is correct
23 Correct 3 ms 3156 KB Output is correct
24 Correct 2 ms 3156 KB Output is correct
25 Correct 3 ms 3244 KB Output is correct
26 Correct 2 ms 3156 KB Output is correct
27 Correct 3 ms 3156 KB Output is correct
28 Correct 3 ms 3156 KB Output is correct
29 Correct 6 ms 3284 KB Output is correct
30 Correct 5 ms 3284 KB Output is correct
31 Correct 5 ms 3284 KB Output is correct
32 Correct 4 ms 3156 KB Output is correct
33 Correct 3 ms 3280 KB Output is correct
34 Correct 5 ms 3284 KB Output is correct
35 Correct 5 ms 3284 KB Output is correct
36 Correct 6 ms 3156 KB Output is correct
37 Correct 4 ms 3284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3156 KB Output is correct
2 Correct 2 ms 3156 KB Output is correct
3 Correct 3 ms 3256 KB Output is correct
4 Correct 3 ms 3248 KB Output is correct
5 Correct 3 ms 3252 KB Output is correct
6 Correct 3 ms 3284 KB Output is correct
7 Correct 3 ms 3252 KB Output is correct
8 Correct 2 ms 3284 KB Output is correct
9 Correct 3 ms 3156 KB Output is correct
10 Correct 3 ms 3284 KB Output is correct
11 Correct 3 ms 3156 KB Output is correct
12 Correct 3 ms 3156 KB Output is correct
13 Correct 2 ms 3156 KB Output is correct
14 Correct 3 ms 3156 KB Output is correct
15 Correct 2 ms 3116 KB Output is correct
16 Correct 4 ms 3284 KB Output is correct
17 Correct 3 ms 3156 KB Output is correct
18 Correct 3 ms 3328 KB Output is correct
19 Correct 2 ms 3156 KB Output is correct
20 Correct 3 ms 3156 KB Output is correct
21 Correct 3 ms 3284 KB Output is correct
22 Correct 3 ms 3284 KB Output is correct
23 Correct 3 ms 3156 KB Output is correct
24 Correct 2 ms 3156 KB Output is correct
25 Correct 3 ms 3244 KB Output is correct
26 Correct 2 ms 3156 KB Output is correct
27 Correct 3 ms 3156 KB Output is correct
28 Correct 3 ms 3156 KB Output is correct
29 Correct 6 ms 3284 KB Output is correct
30 Correct 5 ms 3284 KB Output is correct
31 Correct 5 ms 3284 KB Output is correct
32 Correct 4 ms 3156 KB Output is correct
33 Correct 3 ms 3280 KB Output is correct
34 Correct 5 ms 3284 KB Output is correct
35 Correct 5 ms 3284 KB Output is correct
36 Correct 6 ms 3156 KB Output is correct
37 Correct 4 ms 3284 KB Output is correct
38 Correct 64 ms 5888 KB Output is correct
39 Correct 48 ms 24860 KB Output is correct
40 Correct 138 ms 6188 KB Output is correct
41 Correct 100 ms 4780 KB Output is correct
42 Correct 90 ms 6320 KB Output is correct
43 Correct 28 ms 5044 KB Output is correct
44 Correct 43 ms 3640 KB Output is correct
45 Correct 66 ms 17200 KB Output is correct
46 Correct 64 ms 17208 KB Output is correct
47 Correct 48 ms 20880 KB Output is correct
48 Correct 50 ms 20824 KB Output is correct
49 Correct 55 ms 17344 KB Output is correct
50 Correct 53 ms 17164 KB Output is correct
51 Correct 46 ms 17432 KB Output is correct
52 Correct 55 ms 18124 KB Output is correct
53 Correct 56 ms 4052 KB Output is correct
54 Correct 95 ms 17184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3156 KB Output is correct
2 Correct 2 ms 3156 KB Output is correct
3 Correct 2 ms 3156 KB Output is correct
4 Correct 2 ms 3112 KB Output is correct
5 Correct 8 ms 3260 KB Output is correct
6 Correct 3 ms 3156 KB Output is correct
7 Correct 2 ms 3156 KB Output is correct
8 Correct 2 ms 3116 KB Output is correct
9 Correct 2 ms 3156 KB Output is correct
10 Correct 2 ms 3156 KB Output is correct
11 Correct 2 ms 3156 KB Output is correct
12 Correct 6 ms 3256 KB Output is correct
13 Correct 50 ms 3660 KB Output is correct
14 Correct 48 ms 3980 KB Output is correct
15 Correct 42 ms 3808 KB Output is correct
16 Correct 1694 ms 17224 KB Output is correct
17 Execution timed out 5028 ms 17564 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3156 KB Output is correct
2 Correct 2 ms 3156 KB Output is correct
3 Correct 2 ms 3156 KB Output is correct
4 Correct 12 ms 3376 KB Output is correct
5 Correct 22 ms 3260 KB Output is correct
6 Correct 3 ms 3284 KB Output is correct
7 Correct 3 ms 3264 KB Output is correct
8 Correct 7 ms 3284 KB Output is correct
9 Correct 70 ms 6268 KB Output is correct
10 Correct 48 ms 24496 KB Output is correct
11 Correct 7 ms 3284 KB Output is correct
12 Correct 55 ms 4252 KB Output is correct
13 Execution timed out 5041 ms 28872 KB Time limit exceeded
14 Halted 0 ms 0 KB -