#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
const int N = 100000;
vector<int> g[N+1];
int n;
struct Fenwick{
vector<int> fenw;
int n;
Fenwick(int sz){
n = sz;
fenw.resize(n+5, 0);
};
void add(int i, int x){
for(; i <= n; i+= i & -i){
fenw[i]+= x;
}
}
int pref(int i){
int s = 0;
for(; i > 0; i-= i & -i){
s+= fenw[i];
}
return s;
}
int sum(int l, int r){
return pref(r) - pref(l-1);
}
};
void cl(){
for(int i = 1;i <= n; i++) g[i].clear();
}
/*
*
1
8
1 2
2 3
3 4
4 5
5 6
6 7
7 8
2
3 4
4 8
*/
void solve(){
cin >> n;
for(int i = 1;i < n; i++){
int a, b; cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
int q; cin >> q;
vector< pair<int, int> > query(q);
vector<array<int, 3> > p;
for(int i = 0;i < q; i++){
cin >> query[i].ff >> query[i].ss;
p.push_back({query[i].ff, 0, i});
p.push_back({query[i].ss, 1, i});
}
sort(all(p));
multiset<int> st;
for(auto [x, op, idx] : p){
if(!op){
if(st.empty() == false && *st.rbegin() >= query[idx].ss){
cout << "No";
return;
}
st.insert(query[idx].ss);
}else{
st.erase(st.find(x));
}
}
cout << "Yes";
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t; cin >> t;
while(t--){
solve();
cl();
cout << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Execution timed out |
5025 ms |
2652 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Runtime error |
3 ms |
5212 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Runtime error |
3 ms |
5212 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Runtime error |
3 ms |
5212 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Runtime error |
3 ms |
5212 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Execution timed out |
5074 ms |
2652 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Execution timed out |
5025 ms |
2652 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |