#include "bits/stdc++.h"
using namespace std;
#define int long long
#define fr first
#define sc second
#define eb emplace_back
#define nl "\n"
const int N = 120001;
int n, m;
vector<int> adj[N];
int s[N], t[N];
int from[N];
int use[N];
void dfs(int cur, int par) {
from[cur] = par;
for(auto u : adj[cur]) {
if(u != par)
dfs(u, cur);
}
}
void mod(int a, int b, int v = 1) {
dfs(a, 0);
while(b != 0) {
use[b] += v;
b = from[b];
}
}
void solve() {
cin >> n;
for(int i = 1; i <= n; ++i) {
use[i] = 0;
adj[i].clear();
}
for(int i = 1; i < n; ++i) {
int a, b; cin >> a >> b;
adj[a].eb(b); adj[b].eb(a);
}
cin >> m;
for(int i = 1; i <= m; ++i) {
cin >> s[i] >> t[i];
}
int o[m + 1];
for(int i = 1; i <= m; ++i) o[i] = i;
sort(o + 1, o + m + 1, [&](int l, int r){
return make_pair(s[l], t[l]) < make_pair(s[r], t[r]);
});
for(int i = 1; i < m; ++i) {
int j = o[i], k = o[i + 1];
if(s[k] < t[j]) {
cout << "No" << nl;
return;
}
}
cout << "Yes" << nl;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
cin >> t;
for(int i = 1; i <= t; ++i) {
/* cout << "Case #" << i << nl; */
solve();
/* cout << nl; */
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3156 KB |
Output is correct |
2 |
Incorrect |
2 ms |
3156 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3156 KB |
Output is correct |
2 |
Incorrect |
2 ms |
3156 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3156 KB |
Output is correct |
2 |
Incorrect |
2 ms |
3156 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3156 KB |
Output is correct |
2 |
Incorrect |
2 ms |
3156 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3156 KB |
Output is correct |
2 |
Incorrect |
2 ms |
3156 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3156 KB |
Output is correct |
2 |
Incorrect |
2 ms |
3156 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3156 KB |
Output is correct |
2 |
Incorrect |
2 ms |
3156 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |