This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int te;
cin >> te;
while(te--) {
int n;
cin >> n;
for(int i = 1; i < n; ++i) {
int a, b;
cin >> a >> b;
}
int m;
cin >> m;
vi S(m), T(m);
vector<vi> Ev(n);
for(int i = 0; i < m; ++i) {
int s, t;
cin >> s >> t;
--s; --t;
S[i] = s;
T[i] = t;
Ev[min(s, t)].push_back(i);
Ev[max(s, t)].push_back(-i - 1);
}
int nr1 = 0, nr2 = 0, ok = 1;
for(int i = 0; i < n; ++i) {
for(auto it : Ev[i]) {
if(it >= 0) {
if(S[it] < T[it]) ++nr1;
else ++nr2;
}
}
if(nr1 && nr2) ok = 0;
for(auto it : Ev[i]) {
if(it < 0) {
int i = -it - 1;
if(S[i] < T[i]) --nr1;
else --nr2;
}
}
}
if(ok) cout << "Yes\n";
else cout << "No\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |