답안 #557589

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
557589 2022-05-05T14:18:50 Z DanShaders Jail (JOI22_jail) C++17
49 / 100
5000 ms 506716 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;

namespace x = __gnu_pbds;
template <typename T>
using ordered_set = x::tree<T, x::null_type, less<T>, x::rb_tree_tag, x::tree_order_statistics_node_update>;

template <typename T>
using normal_queue = priority_queue<T, vector<T>, greater<>>;

#define all(x) begin(x), end(x)
#define sz(x) ((int) (x).size())
#define x first
#define y second
using ll = long long;
using ld = long double;

const int N = 1.25e5, M = 5 * N;

int s[N], t[N];
vector<int> g[N], g2[M];

char used[N];
vector<int> path;

bool dfs_cycle(int u) {
	if (used[u] == 1) {
		return false;
	}
	used[u] = 1;
	for (int v : g2[u]) {
		if (used[v] != 2 && !dfs_cycle(v)) {
			return false;
		}
	}
	used[u] = 2;
	return true;
}

bool dfs(int u, int w, int p = -1) {
	path.push_back(u);
	if (u == w) {
		return true;
	}
	for (int v : g[u]) {
		if (v != p && dfs(v, w, u)) {
			return true;
		}
	}
	path.pop_back();
	return false;
}

signed main() {
	cin.tie(0)->sync_with_stdio(0);
	int testcases;
	cin >> testcases;
	while (testcases--) {
		int n, m;
		cin >> n;
		for (int i = 0; i < 5 * n; ++i) {
			g2[i].clear();
		}
		for (int i = 0; i < n; ++i) {
			g[i].clear();
		}
		for (int i = 1; i < n; ++i) {
			int u, v;
			cin >> u >> v;
			g[--u].push_back(--v);
			g[v].push_back(u);
		}
		cin >> m;
		for (int i = 0; i < m; ++i) {
			cin >> s[i] >> t[i];
			--s[i], --t[i];
			
			path.clear();
			dfs(s[i], t[i]);

			for (int u : path) {
				if (u != s[i]) {
					g2[4 * n + i].push_back(n + u);
				}
			}
			for (int u : path) {
				if (u != t[i]) {
					g2[3 * n + u].push_back(4 * n + i);
				}
			}
			g2[n + s[i]].push_back(4 * n + i);
			g2[4 * n + i].push_back(3 * n + t[i]);
		}
		// for (int i = 0; i < 5 * n; ++i) {
		// 	for (int v : g[i]) {
		// 		cout << i << " -> " << v << endl;
		// 	}
		// }
		fill(used, used + 5 * n, 0);
		bool flag = true;
		for (int i = 0; i < 5 * n; ++i) {
			if (!used[i]) {
				flag &= dfs_cycle(i);
			}
		}
		cout << (flag ? "Yes\n" : "No\n");
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 17876 KB Output is correct
2 Correct 11 ms 17876 KB Output is correct
3 Correct 9 ms 17940 KB Output is correct
4 Correct 19 ms 18088 KB Output is correct
5 Correct 30 ms 17964 KB Output is correct
6 Correct 10 ms 18004 KB Output is correct
7 Correct 13 ms 17992 KB Output is correct
8 Correct 14 ms 18072 KB Output is correct
9 Correct 441 ms 45792 KB Output is correct
10 Runtime error 3029 ms 506716 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 17876 KB Output is correct
2 Correct 9 ms 17876 KB Output is correct
3 Correct 11 ms 17972 KB Output is correct
4 Correct 11 ms 17876 KB Output is correct
5 Correct 14 ms 17928 KB Output is correct
6 Correct 11 ms 17940 KB Output is correct
7 Correct 11 ms 17936 KB Output is correct
8 Correct 11 ms 17876 KB Output is correct
9 Correct 11 ms 17876 KB Output is correct
10 Correct 10 ms 17876 KB Output is correct
11 Correct 10 ms 17884 KB Output is correct
12 Correct 9 ms 17876 KB Output is correct
13 Correct 10 ms 17876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 17876 KB Output is correct
2 Correct 9 ms 17876 KB Output is correct
3 Correct 11 ms 17972 KB Output is correct
4 Correct 11 ms 17876 KB Output is correct
5 Correct 14 ms 17928 KB Output is correct
6 Correct 11 ms 17940 KB Output is correct
7 Correct 11 ms 17936 KB Output is correct
8 Correct 11 ms 17876 KB Output is correct
9 Correct 11 ms 17876 KB Output is correct
10 Correct 10 ms 17876 KB Output is correct
11 Correct 10 ms 17884 KB Output is correct
12 Correct 9 ms 17876 KB Output is correct
13 Correct 10 ms 17876 KB Output is correct
14 Correct 9 ms 17876 KB Output is correct
15 Correct 10 ms 17876 KB Output is correct
16 Correct 13 ms 17876 KB Output is correct
17 Correct 14 ms 17856 KB Output is correct
18 Correct 12 ms 17876 KB Output is correct
19 Correct 12 ms 17940 KB Output is correct
20 Correct 13 ms 17876 KB Output is correct
21 Correct 14 ms 17872 KB Output is correct
22 Correct 11 ms 17876 KB Output is correct
23 Correct 11 ms 17948 KB Output is correct
24 Correct 10 ms 17964 KB Output is correct
25 Correct 10 ms 17876 KB Output is correct
26 Correct 10 ms 17876 KB Output is correct
27 Correct 10 ms 17900 KB Output is correct
28 Correct 10 ms 17876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 17876 KB Output is correct
2 Correct 9 ms 17876 KB Output is correct
3 Correct 11 ms 17972 KB Output is correct
4 Correct 11 ms 17876 KB Output is correct
5 Correct 14 ms 17928 KB Output is correct
6 Correct 11 ms 17940 KB Output is correct
7 Correct 11 ms 17936 KB Output is correct
8 Correct 11 ms 17876 KB Output is correct
9 Correct 11 ms 17876 KB Output is correct
10 Correct 10 ms 17876 KB Output is correct
11 Correct 10 ms 17884 KB Output is correct
12 Correct 9 ms 17876 KB Output is correct
13 Correct 10 ms 17876 KB Output is correct
14 Correct 9 ms 17876 KB Output is correct
15 Correct 10 ms 17876 KB Output is correct
16 Correct 13 ms 17876 KB Output is correct
17 Correct 14 ms 17856 KB Output is correct
18 Correct 12 ms 17876 KB Output is correct
19 Correct 12 ms 17940 KB Output is correct
20 Correct 13 ms 17876 KB Output is correct
21 Correct 14 ms 17872 KB Output is correct
22 Correct 11 ms 17876 KB Output is correct
23 Correct 11 ms 17948 KB Output is correct
24 Correct 10 ms 17964 KB Output is correct
25 Correct 10 ms 17876 KB Output is correct
26 Correct 10 ms 17876 KB Output is correct
27 Correct 10 ms 17900 KB Output is correct
28 Correct 10 ms 17876 KB Output is correct
29 Correct 14 ms 18260 KB Output is correct
30 Correct 14 ms 17984 KB Output is correct
31 Correct 12 ms 18004 KB Output is correct
32 Correct 14 ms 17940 KB Output is correct
33 Correct 12 ms 17876 KB Output is correct
34 Correct 15 ms 17876 KB Output is correct
35 Correct 15 ms 18004 KB Output is correct
36 Correct 14 ms 17936 KB Output is correct
37 Correct 12 ms 17960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 17876 KB Output is correct
2 Correct 9 ms 17876 KB Output is correct
3 Correct 11 ms 17972 KB Output is correct
4 Correct 11 ms 17876 KB Output is correct
5 Correct 14 ms 17928 KB Output is correct
6 Correct 11 ms 17940 KB Output is correct
7 Correct 11 ms 17936 KB Output is correct
8 Correct 11 ms 17876 KB Output is correct
9 Correct 11 ms 17876 KB Output is correct
10 Correct 10 ms 17876 KB Output is correct
11 Correct 10 ms 17884 KB Output is correct
12 Correct 9 ms 17876 KB Output is correct
13 Correct 10 ms 17876 KB Output is correct
14 Correct 9 ms 17876 KB Output is correct
15 Correct 10 ms 17876 KB Output is correct
16 Correct 13 ms 17876 KB Output is correct
17 Correct 14 ms 17856 KB Output is correct
18 Correct 12 ms 17876 KB Output is correct
19 Correct 12 ms 17940 KB Output is correct
20 Correct 13 ms 17876 KB Output is correct
21 Correct 14 ms 17872 KB Output is correct
22 Correct 11 ms 17876 KB Output is correct
23 Correct 11 ms 17948 KB Output is correct
24 Correct 10 ms 17964 KB Output is correct
25 Correct 10 ms 17876 KB Output is correct
26 Correct 10 ms 17876 KB Output is correct
27 Correct 10 ms 17900 KB Output is correct
28 Correct 10 ms 17876 KB Output is correct
29 Correct 14 ms 18260 KB Output is correct
30 Correct 14 ms 17984 KB Output is correct
31 Correct 12 ms 18004 KB Output is correct
32 Correct 14 ms 17940 KB Output is correct
33 Correct 12 ms 17876 KB Output is correct
34 Correct 15 ms 17876 KB Output is correct
35 Correct 15 ms 18004 KB Output is correct
36 Correct 14 ms 17936 KB Output is correct
37 Correct 12 ms 17960 KB Output is correct
38 Correct 431 ms 45540 KB Output is correct
39 Runtime error 2994 ms 506616 KB Execution killed with signal 11
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 17948 KB Output is correct
2 Correct 10 ms 17912 KB Output is correct
3 Correct 10 ms 17876 KB Output is correct
4 Correct 9 ms 17876 KB Output is correct
5 Correct 15 ms 17876 KB Output is correct
6 Correct 11 ms 17872 KB Output is correct
7 Correct 10 ms 17876 KB Output is correct
8 Correct 10 ms 17876 KB Output is correct
9 Correct 10 ms 17876 KB Output is correct
10 Correct 10 ms 17876 KB Output is correct
11 Correct 11 ms 17876 KB Output is correct
12 Correct 12 ms 18004 KB Output is correct
13 Correct 40 ms 17972 KB Output is correct
14 Correct 55 ms 17964 KB Output is correct
15 Correct 46 ms 17976 KB Output is correct
16 Execution timed out 5096 ms 22640 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 17876 KB Output is correct
2 Correct 11 ms 17876 KB Output is correct
3 Correct 9 ms 17940 KB Output is correct
4 Correct 19 ms 18088 KB Output is correct
5 Correct 30 ms 17964 KB Output is correct
6 Correct 10 ms 18004 KB Output is correct
7 Correct 13 ms 17992 KB Output is correct
8 Correct 14 ms 18072 KB Output is correct
9 Correct 441 ms 45792 KB Output is correct
10 Runtime error 3029 ms 506716 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -