Submission #884867

# Submission time Handle Problem Language Result Execution time Memory
884867 2023-12-08T15:05:23 Z MinaRagy06 Jail (JOI22_jail) C++17
0 / 100
5 ms 604 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]{};
		for (int i = 0; i < m; i++) {
			int s, e;
			cin >> s >> e;
			s--, e--;
			if (s < e) {
				st[s]++;
				en[e]++;
			} else {
				st2[s]++;
				en2[e]++;
			}
		}
		int cnt[n]{}, c = 0;
		for (int i = 0; i < n; i++) {
			c += st[i];
			if (c) {
				cnt[i]++;
			}
			c -= en[i];
		}
		c = 0;
		bool ok = 1;
		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;
}

# Verdict Execution time Memory Grader output
1 Correct 1 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 Incorrect 5 ms 604 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 1 ms 496 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Incorrect 3 ms 344 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 Incorrect 5 ms 604 KB Output isn't correct
5 Halted 0 ms 0 KB -