답안 #630205

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
630205 2022-08-16T02:45:19 Z flappybird Jail (JOI22_jail) C++17
49 / 100
5000 ms 11476 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 121010
#define MAXS 20
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
vector<int> adj[MAX];
vector<int> graph[MAX];
int S[MAX];
int T[MAX];
int deg[MAX];
bool chk(int x, int ban, int e, int p = 0) {
	if (x == ban) return false;
	if (x == e) return true;
	for (auto v : adj[x]) {
		if (v == p) continue;
		if (v == ban) continue;
		if (chk(v, ban, e, x)) return true;
	}
	return false;
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int Q;
	cin >> Q;
	while (Q--) {
		int N;
		cin >> N;
		int i, a, b;
		for (i = 1; i <= N; i++) adj[i].clear();
		for (i = 1; i < N; i++) cin >> a >> b, adj[a].push_back(b), adj[b].push_back(a);
		int M;
		cin >> M;
		for (i = 1; i <= M; i++) cin >> S[i] >> T[i], deg[i] = 0, graph[i].clear();
		int j;
		for (i = 1; i <= M; i++) {
			for (j = 1; j <= M; j++) {
				if (i == j) continue;
				int a, b, c;
				a = S[i];
				b = T[i];
				c = T[j];
				if (!chk(a, c, b)) {
					graph[i].push_back(j);
					deg[j]++;
				}
			}
		}
		for (i = 1; i <= M; i++) {
			for (j = 1; j <= M; j++) {
				if (i == j) continue;
				int a, b, c;
				a = S[i];
				b = T[i];
				c = S[j];
				if (!chk(a, c, b)) {
					graph[j].push_back(i);
					deg[i]++;
				}
			}
		}
		int cnt = 0;
		queue<int> q;
		for (i = 1; i <= M; i++) if (!deg[i]) q.push(i);
		while (q.size()) {
			int t = q.front();
			cnt++;
			q.pop();
			for (auto v : graph[t]) {
				deg[v]--;
				if (!deg[v]) q.push(v);
			}
		}
		if (cnt == M) cout << "Yes" << ln;
		else cout << "No" << ln;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5972 KB Output is correct
2 Correct 3 ms 5972 KB Output is correct
3 Correct 3 ms 5972 KB Output is correct
4 Correct 12 ms 6028 KB Output is correct
5 Correct 20 ms 5972 KB Output is correct
6 Correct 4 ms 5972 KB Output is correct
7 Correct 5 ms 5972 KB Output is correct
8 Correct 195 ms 6204 KB Output is correct
9 Execution timed out 5013 ms 6544 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5972 KB Output is correct
2 Correct 3 ms 5972 KB Output is correct
3 Correct 4 ms 5972 KB Output is correct
4 Correct 4 ms 6032 KB Output is correct
5 Correct 3 ms 5972 KB Output is correct
6 Correct 6 ms 5972 KB Output is correct
7 Correct 3 ms 5972 KB Output is correct
8 Correct 4 ms 5972 KB Output is correct
9 Correct 4 ms 6020 KB Output is correct
10 Correct 4 ms 5972 KB Output is correct
11 Correct 3 ms 6028 KB Output is correct
12 Correct 3 ms 5972 KB Output is correct
13 Correct 3 ms 5972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5972 KB Output is correct
2 Correct 3 ms 5972 KB Output is correct
3 Correct 4 ms 5972 KB Output is correct
4 Correct 4 ms 6032 KB Output is correct
5 Correct 3 ms 5972 KB Output is correct
6 Correct 6 ms 5972 KB Output is correct
7 Correct 3 ms 5972 KB Output is correct
8 Correct 4 ms 5972 KB Output is correct
9 Correct 4 ms 6020 KB Output is correct
10 Correct 4 ms 5972 KB Output is correct
11 Correct 3 ms 6028 KB Output is correct
12 Correct 3 ms 5972 KB Output is correct
13 Correct 3 ms 5972 KB Output is correct
14 Correct 4 ms 5972 KB Output is correct
15 Correct 3 ms 5972 KB Output is correct
16 Correct 5 ms 5972 KB Output is correct
17 Correct 4 ms 6032 KB Output is correct
18 Correct 6 ms 6028 KB Output is correct
19 Correct 3 ms 5984 KB Output is correct
20 Correct 5 ms 5972 KB Output is correct
21 Correct 5 ms 5988 KB Output is correct
22 Correct 5 ms 5972 KB Output is correct
23 Correct 3 ms 5908 KB Output is correct
24 Correct 3 ms 5972 KB Output is correct
25 Correct 5 ms 5972 KB Output is correct
26 Correct 4 ms 5972 KB Output is correct
27 Correct 5 ms 5972 KB Output is correct
28 Correct 3 ms 5972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5972 KB Output is correct
2 Correct 3 ms 5972 KB Output is correct
3 Correct 4 ms 5972 KB Output is correct
4 Correct 4 ms 6032 KB Output is correct
5 Correct 3 ms 5972 KB Output is correct
6 Correct 6 ms 5972 KB Output is correct
7 Correct 3 ms 5972 KB Output is correct
8 Correct 4 ms 5972 KB Output is correct
9 Correct 4 ms 6020 KB Output is correct
10 Correct 4 ms 5972 KB Output is correct
11 Correct 3 ms 6028 KB Output is correct
12 Correct 3 ms 5972 KB Output is correct
13 Correct 3 ms 5972 KB Output is correct
14 Correct 4 ms 5972 KB Output is correct
15 Correct 3 ms 5972 KB Output is correct
16 Correct 5 ms 5972 KB Output is correct
17 Correct 4 ms 6032 KB Output is correct
18 Correct 6 ms 6028 KB Output is correct
19 Correct 3 ms 5984 KB Output is correct
20 Correct 5 ms 5972 KB Output is correct
21 Correct 5 ms 5988 KB Output is correct
22 Correct 5 ms 5972 KB Output is correct
23 Correct 3 ms 5908 KB Output is correct
24 Correct 3 ms 5972 KB Output is correct
25 Correct 5 ms 5972 KB Output is correct
26 Correct 4 ms 5972 KB Output is correct
27 Correct 5 ms 5972 KB Output is correct
28 Correct 3 ms 5972 KB Output is correct
29 Correct 195 ms 6084 KB Output is correct
30 Correct 112 ms 6032 KB Output is correct
31 Correct 125 ms 6160 KB Output is correct
32 Correct 79 ms 6020 KB Output is correct
33 Correct 15 ms 6032 KB Output is correct
34 Correct 218 ms 6036 KB Output is correct
35 Correct 198 ms 5972 KB Output is correct
36 Correct 219 ms 6028 KB Output is correct
37 Correct 102 ms 5972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5972 KB Output is correct
2 Correct 3 ms 5972 KB Output is correct
3 Correct 4 ms 5972 KB Output is correct
4 Correct 4 ms 6032 KB Output is correct
5 Correct 3 ms 5972 KB Output is correct
6 Correct 6 ms 5972 KB Output is correct
7 Correct 3 ms 5972 KB Output is correct
8 Correct 4 ms 5972 KB Output is correct
9 Correct 4 ms 6020 KB Output is correct
10 Correct 4 ms 5972 KB Output is correct
11 Correct 3 ms 6028 KB Output is correct
12 Correct 3 ms 5972 KB Output is correct
13 Correct 3 ms 5972 KB Output is correct
14 Correct 4 ms 5972 KB Output is correct
15 Correct 3 ms 5972 KB Output is correct
16 Correct 5 ms 5972 KB Output is correct
17 Correct 4 ms 6032 KB Output is correct
18 Correct 6 ms 6028 KB Output is correct
19 Correct 3 ms 5984 KB Output is correct
20 Correct 5 ms 5972 KB Output is correct
21 Correct 5 ms 5988 KB Output is correct
22 Correct 5 ms 5972 KB Output is correct
23 Correct 3 ms 5908 KB Output is correct
24 Correct 3 ms 5972 KB Output is correct
25 Correct 5 ms 5972 KB Output is correct
26 Correct 4 ms 5972 KB Output is correct
27 Correct 5 ms 5972 KB Output is correct
28 Correct 3 ms 5972 KB Output is correct
29 Correct 195 ms 6084 KB Output is correct
30 Correct 112 ms 6032 KB Output is correct
31 Correct 125 ms 6160 KB Output is correct
32 Correct 79 ms 6020 KB Output is correct
33 Correct 15 ms 6032 KB Output is correct
34 Correct 218 ms 6036 KB Output is correct
35 Correct 198 ms 5972 KB Output is correct
36 Correct 219 ms 6028 KB Output is correct
37 Correct 102 ms 5972 KB Output is correct
38 Execution timed out 5037 ms 6508 KB Time limit exceeded
39 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5972 KB Output is correct
2 Correct 3 ms 5972 KB Output is correct
3 Correct 3 ms 5972 KB Output is correct
4 Correct 4 ms 5972 KB Output is correct
5 Correct 15 ms 5972 KB Output is correct
6 Correct 6 ms 5972 KB Output is correct
7 Correct 4 ms 5972 KB Output is correct
8 Correct 3 ms 5972 KB Output is correct
9 Correct 5 ms 6016 KB Output is correct
10 Correct 4 ms 5972 KB Output is correct
11 Correct 3 ms 6016 KB Output is correct
12 Correct 157 ms 6056 KB Output is correct
13 Correct 1157 ms 6152 KB Output is correct
14 Correct 593 ms 6052 KB Output is correct
15 Correct 956 ms 6132 KB Output is correct
16 Execution timed out 5064 ms 11476 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5972 KB Output is correct
2 Correct 3 ms 5972 KB Output is correct
3 Correct 3 ms 5972 KB Output is correct
4 Correct 12 ms 6028 KB Output is correct
5 Correct 20 ms 5972 KB Output is correct
6 Correct 4 ms 5972 KB Output is correct
7 Correct 5 ms 5972 KB Output is correct
8 Correct 195 ms 6204 KB Output is correct
9 Execution timed out 5013 ms 6544 KB Time limit exceeded
10 Halted 0 ms 0 KB -