답안 #560965

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
560965 2022-05-12T06:00:03 Z 8e7 Jail (JOI22_jail) C++17
72 / 100
3651 ms 1048576 KB
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 120005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
vector<int> adj[maxn], g[maxn], pnt[maxn];
int anc[18][maxn], dep[maxn], deg[maxn];
pii ed[maxn];
void dfs(int n, int par, int d) {
	anc[0][n] = par;
	dep[n] = d;	
	for (int v:adj[n]) {
		if (v != par) {
			dfs(v, n, d + 1);
		}
	}
}
int main() {
	io
	int T;
	cin >> T;
	while (T--) {

		int n;
		cin >> n;
		for (int i = 1;i <= n;i++) {
			adj[i].clear();
			g[i].clear();
			pnt[i].clear();
			deg[i] = 0;
		}
		for (int i = 0;i < n - 1;i++) {
			int u,v;
			cin >> u >> v;
			adj[u].push_back(v);
			adj[v].push_back(u);
		}
		dfs(1, 0, 0);
		int m;
		cin >> m;
		auto addedge = [&] (int u, int v) {
			g[u].push_back(v);
			deg[v]++;
		};
		for (int i = 1;i <= m;i++) {
			int u, v;
			cin >> u >> v;
			int tu = u, tv = v;	
			while (tu != tv) {
				if (dep[tu] > dep[tv]) pnt[tu].push_back(i), tu = anc[0][tu];
				else pnt[tv].push_back(i), tv = anc[0][tv];
			}
			pnt[tu].push_back(i);
			ed[i] = {u, v};	
		}
		for (int i = 1;i <= m;i++) {
			for (int k:pnt[ed[i].ff]) {
				if (k != i) addedge(k, i);
			}
			for (int k:pnt[ed[i].ss]) {
				if (k != i) addedge(i, k);
			}
		}
		queue<int> que;
		for (int i = 1;i <= n;i++) {
			if (deg[i] == 0) que.push(i);
		}
		int cnt = 0;
		while (que.size()) {
			int cur = que.front();que.pop();
			cnt++;
			for (int v:g[cur]) {
				if (--deg[v] == 0) que.push(v);
			}
		}
		cout << (cnt == n ? "Yes" : "No") << "\n";	
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8788 KB Output is correct
2 Correct 4 ms 8788 KB Output is correct
3 Correct 4 ms 8780 KB Output is correct
4 Correct 13 ms 8776 KB Output is correct
5 Correct 23 ms 8820 KB Output is correct
6 Correct 5 ms 8788 KB Output is correct
7 Correct 5 ms 8788 KB Output is correct
8 Correct 6 ms 8916 KB Output is correct
9 Correct 123 ms 23072 KB Output is correct
10 Correct 1254 ms 261052 KB Output is correct
11 Correct 9 ms 8744 KB Output is correct
12 Correct 42 ms 8944 KB Output is correct
13 Correct 201 ms 84592 KB Output is correct
14 Correct 251 ms 115000 KB Output is correct
15 Runtime error 3651 ms 1048576 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8796 KB Output is correct
2 Correct 5 ms 8784 KB Output is correct
3 Correct 6 ms 8804 KB Output is correct
4 Correct 7 ms 8788 KB Output is correct
5 Correct 6 ms 8856 KB Output is correct
6 Correct 6 ms 8788 KB Output is correct
7 Correct 6 ms 8804 KB Output is correct
8 Correct 7 ms 8788 KB Output is correct
9 Correct 6 ms 8788 KB Output is correct
10 Correct 6 ms 8788 KB Output is correct
11 Correct 6 ms 8800 KB Output is correct
12 Correct 5 ms 8728 KB Output is correct
13 Correct 5 ms 8788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8796 KB Output is correct
2 Correct 5 ms 8784 KB Output is correct
3 Correct 6 ms 8804 KB Output is correct
4 Correct 7 ms 8788 KB Output is correct
5 Correct 6 ms 8856 KB Output is correct
6 Correct 6 ms 8788 KB Output is correct
7 Correct 6 ms 8804 KB Output is correct
8 Correct 7 ms 8788 KB Output is correct
9 Correct 6 ms 8788 KB Output is correct
10 Correct 6 ms 8788 KB Output is correct
11 Correct 6 ms 8800 KB Output is correct
12 Correct 5 ms 8728 KB Output is correct
13 Correct 5 ms 8788 KB Output is correct
14 Correct 5 ms 8788 KB Output is correct
15 Correct 6 ms 8732 KB Output is correct
16 Correct 6 ms 8800 KB Output is correct
17 Correct 6 ms 8788 KB Output is correct
18 Correct 6 ms 8800 KB Output is correct
19 Correct 5 ms 8788 KB Output is correct
20 Correct 6 ms 8800 KB Output is correct
21 Correct 6 ms 8796 KB Output is correct
22 Correct 6 ms 8788 KB Output is correct
23 Correct 6 ms 8788 KB Output is correct
24 Correct 5 ms 8808 KB Output is correct
25 Correct 6 ms 8848 KB Output is correct
26 Correct 6 ms 8792 KB Output is correct
27 Correct 6 ms 8928 KB Output is correct
28 Correct 4 ms 8788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8796 KB Output is correct
2 Correct 5 ms 8784 KB Output is correct
3 Correct 6 ms 8804 KB Output is correct
4 Correct 7 ms 8788 KB Output is correct
5 Correct 6 ms 8856 KB Output is correct
6 Correct 6 ms 8788 KB Output is correct
7 Correct 6 ms 8804 KB Output is correct
8 Correct 7 ms 8788 KB Output is correct
9 Correct 6 ms 8788 KB Output is correct
10 Correct 6 ms 8788 KB Output is correct
11 Correct 6 ms 8800 KB Output is correct
12 Correct 5 ms 8728 KB Output is correct
13 Correct 5 ms 8788 KB Output is correct
14 Correct 5 ms 8788 KB Output is correct
15 Correct 6 ms 8732 KB Output is correct
16 Correct 6 ms 8800 KB Output is correct
17 Correct 6 ms 8788 KB Output is correct
18 Correct 6 ms 8800 KB Output is correct
19 Correct 5 ms 8788 KB Output is correct
20 Correct 6 ms 8800 KB Output is correct
21 Correct 6 ms 8796 KB Output is correct
22 Correct 6 ms 8788 KB Output is correct
23 Correct 6 ms 8788 KB Output is correct
24 Correct 5 ms 8808 KB Output is correct
25 Correct 6 ms 8848 KB Output is correct
26 Correct 6 ms 8792 KB Output is correct
27 Correct 6 ms 8928 KB Output is correct
28 Correct 4 ms 8788 KB Output is correct
29 Correct 7 ms 9044 KB Output is correct
30 Correct 7 ms 8800 KB Output is correct
31 Correct 7 ms 8928 KB Output is correct
32 Correct 6 ms 8788 KB Output is correct
33 Correct 6 ms 8792 KB Output is correct
34 Correct 6 ms 8788 KB Output is correct
35 Correct 8 ms 8932 KB Output is correct
36 Correct 6 ms 8788 KB Output is correct
37 Correct 6 ms 8788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8796 KB Output is correct
2 Correct 5 ms 8784 KB Output is correct
3 Correct 6 ms 8804 KB Output is correct
4 Correct 7 ms 8788 KB Output is correct
5 Correct 6 ms 8856 KB Output is correct
6 Correct 6 ms 8788 KB Output is correct
7 Correct 6 ms 8804 KB Output is correct
8 Correct 7 ms 8788 KB Output is correct
9 Correct 6 ms 8788 KB Output is correct
10 Correct 6 ms 8788 KB Output is correct
11 Correct 6 ms 8800 KB Output is correct
12 Correct 5 ms 8728 KB Output is correct
13 Correct 5 ms 8788 KB Output is correct
14 Correct 5 ms 8788 KB Output is correct
15 Correct 6 ms 8732 KB Output is correct
16 Correct 6 ms 8800 KB Output is correct
17 Correct 6 ms 8788 KB Output is correct
18 Correct 6 ms 8800 KB Output is correct
19 Correct 5 ms 8788 KB Output is correct
20 Correct 6 ms 8800 KB Output is correct
21 Correct 6 ms 8796 KB Output is correct
22 Correct 6 ms 8788 KB Output is correct
23 Correct 6 ms 8788 KB Output is correct
24 Correct 5 ms 8808 KB Output is correct
25 Correct 6 ms 8848 KB Output is correct
26 Correct 6 ms 8792 KB Output is correct
27 Correct 6 ms 8928 KB Output is correct
28 Correct 4 ms 8788 KB Output is correct
29 Correct 7 ms 9044 KB Output is correct
30 Correct 7 ms 8800 KB Output is correct
31 Correct 7 ms 8928 KB Output is correct
32 Correct 6 ms 8788 KB Output is correct
33 Correct 6 ms 8792 KB Output is correct
34 Correct 6 ms 8788 KB Output is correct
35 Correct 8 ms 8932 KB Output is correct
36 Correct 6 ms 8788 KB Output is correct
37 Correct 6 ms 8788 KB Output is correct
38 Correct 128 ms 23244 KB Output is correct
39 Correct 1038 ms 261196 KB Output is correct
40 Correct 79 ms 16248 KB Output is correct
41 Correct 34 ms 9652 KB Output is correct
42 Correct 57 ms 13696 KB Output is correct
43 Correct 26 ms 9548 KB Output is correct
44 Correct 12 ms 9352 KB Output is correct
45 Correct 55 ms 15624 KB Output is correct
46 Correct 47 ms 15368 KB Output is correct
47 Correct 179 ms 64316 KB Output is correct
48 Correct 177 ms 65468 KB Output is correct
49 Correct 58 ms 17600 KB Output is correct
50 Correct 56 ms 17652 KB Output is correct
51 Correct 39 ms 15140 KB Output is correct
52 Correct 38 ms 15232 KB Output is correct
53 Correct 15 ms 9428 KB Output is correct
54 Correct 73 ms 14900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8788 KB Output is correct
2 Correct 5 ms 8720 KB Output is correct
3 Correct 5 ms 8788 KB Output is correct
4 Correct 5 ms 8792 KB Output is correct
5 Correct 10 ms 8924 KB Output is correct
6 Correct 7 ms 8788 KB Output is correct
7 Correct 5 ms 8800 KB Output is correct
8 Correct 5 ms 8916 KB Output is correct
9 Correct 5 ms 8788 KB Output is correct
10 Correct 6 ms 8788 KB Output is correct
11 Correct 5 ms 8788 KB Output is correct
12 Correct 7 ms 8792 KB Output is correct
13 Correct 20 ms 8924 KB Output is correct
14 Correct 27 ms 8916 KB Output is correct
15 Correct 28 ms 8972 KB Output is correct
16 Correct 62 ms 16740 KB Output is correct
17 Correct 146 ms 27808 KB Output is correct
18 Correct 394 ms 54972 KB Output is correct
19 Correct 70 ms 19388 KB Output is correct
20 Correct 81 ms 18612 KB Output is correct
21 Correct 76 ms 18684 KB Output is correct
22 Correct 136 ms 31164 KB Output is correct
23 Correct 118 ms 30932 KB Output is correct
24 Correct 134 ms 29060 KB Output is correct
25 Correct 115 ms 29180 KB Output is correct
26 Correct 120 ms 30840 KB Output is correct
27 Correct 152 ms 24372 KB Output is correct
28 Correct 144 ms 24644 KB Output is correct
29 Correct 148 ms 25928 KB Output is correct
30 Correct 93 ms 22856 KB Output is correct
31 Correct 94 ms 22192 KB Output is correct
32 Correct 101 ms 22880 KB Output is correct
33 Correct 97 ms 21944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8788 KB Output is correct
2 Correct 4 ms 8788 KB Output is correct
3 Correct 4 ms 8780 KB Output is correct
4 Correct 13 ms 8776 KB Output is correct
5 Correct 23 ms 8820 KB Output is correct
6 Correct 5 ms 8788 KB Output is correct
7 Correct 5 ms 8788 KB Output is correct
8 Correct 6 ms 8916 KB Output is correct
9 Correct 123 ms 23072 KB Output is correct
10 Correct 1254 ms 261052 KB Output is correct
11 Correct 9 ms 8744 KB Output is correct
12 Correct 42 ms 8944 KB Output is correct
13 Correct 201 ms 84592 KB Output is correct
14 Correct 251 ms 115000 KB Output is correct
15 Runtime error 3651 ms 1048576 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -