답안 #884868

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
884868 2023-12-08T15:12:25 Z MinaRagy06 Jail (JOI22_jail) C++17
5 / 100
41 ms 6608 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		for (int i = 1, u, v; i < n; i++) {
			cin >> u >> v;
			u--, v--;
		}
		int m;
		cin >> m;
		int st[n]{}, en[n]{}, st2[n]{}, en2[n]{};
		vector<array<int, 2>> v;
		for (int i = 0; i < m; i++) {
			int s, e;
			cin >> s >> e;
			s--, e--;
			v.push_back({min(s, e), max(s, e)});
			if (s < e) {
				st[s]++;
				en[e]++;
			} else {
				st2[s]++;
				en2[e]++;
			}
		}
		bool ok = 1;
		sort(v.begin(), v.end());
		int mn = 1e9;
		for (int i = v.size() - 1; i >= 0; i--) {
			if (mn < v[i][1]) {
				ok = 0;
			}
			mn = min(mn, v[i][1]);
		}
		int cnt[n]{}, c = 0;
		for (int i = 0; i < n; i++) {
			c += st[i];
			if (c) {
				cnt[i]++;
			}
			c -= en[i];
		}
		c = 0;
		for (int i = n - 1; i >= 0; i--) {
			c += st2[i];
			if (c && cnt[i]) {
				ok = 0;
			}
			c -= en2[i];
		}
		cout << (ok? "Yes\n" : "No\n");
	}
	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 5 ms 600 KB Output is correct
5 Correct 11 ms 860 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 14 ms 1116 KB Output is correct
10 Correct 19 ms 3676 KB Output is correct
11 Correct 3 ms 604 KB Output is correct
12 Correct 15 ms 1236 KB Output is correct
13 Correct 22 ms 4432 KB Output is correct
14 Correct 23 ms 5164 KB Output is correct
15 Correct 25 ms 5296 KB Output is correct
16 Correct 41 ms 6608 KB Output is correct
17 Correct 24 ms 5308 KB Output is correct
18 Correct 32 ms 6608 KB Output is correct
19 Correct 24 ms 5300 KB Output is correct
20 Correct 24 ms 5328 KB Output is correct
21 Correct 24 ms 5332 KB Output is correct
22 Correct 24 ms 5408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 1 ms 472 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 1 ms 472 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 1 ms 472 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 1 ms 472 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Incorrect 1 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 5 ms 600 KB Output is correct
5 Correct 11 ms 860 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 14 ms 1116 KB Output is correct
10 Correct 19 ms 3676 KB Output is correct
11 Correct 3 ms 604 KB Output is correct
12 Correct 15 ms 1236 KB Output is correct
13 Correct 22 ms 4432 KB Output is correct
14 Correct 23 ms 5164 KB Output is correct
15 Correct 25 ms 5296 KB Output is correct
16 Correct 41 ms 6608 KB Output is correct
17 Correct 24 ms 5308 KB Output is correct
18 Correct 32 ms 6608 KB Output is correct
19 Correct 24 ms 5300 KB Output is correct
20 Correct 24 ms 5328 KB Output is correct
21 Correct 24 ms 5332 KB Output is correct
22 Correct 24 ms 5408 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Incorrect 1 ms 472 KB Output isn't correct
27 Halted 0 ms 0 KB -