//#pragma GCC optimize("Ofast,unroll-loops,O3")
//#pragma GCC optimize("avx,avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,fma,tune=native")
#include<bits/stdc++.h>
//#include<bits/extc++.h>
//#pragma pack(1)
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define int long long
#define pii pair<int,int>
#define x first
#define y second
#define N 120015
using namespace std;
//using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//typedef tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> order_multiset;
//typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> order_set;
int n,m,s1[N],s2[N];
pii pos[N];
vector<pii>v1,v2;
signed main(){
fast
int q; cin>>q;
while (q--){
cin>>n;
v1.clear(); v2.clear();
for (int i=0;i<=n+5;i++){
s1[i]=0; s2[i]=0;
}
for (int i=1;i<n;i++){
int a,b; cin>>a>>b;
}
cin>>m;
for (int i=1;i<=m;i++){
cin>>pos[i].x>>pos[i].y;
if (pos[i].x<pos[i].y){
s1[pos[i].x]++;
s1[pos[i].y+1]--;
v1.push_back(pos[i]);
}
else {
s2[pos[i].x]++;
s2[pos[i].y-1]--;
v2.push_back(pos[i]);
}
}
for (int i=1;i<=n;i++)
s1[i]+=s1[i-1];
for (int i=n;i>=1;i--)
s2[i]+=s2[i+1];
bool flag=1;
for (int i=1;i<=n;i++){
if (s1[i]&&s2[i]) flag=0;
}
sort(v1.begin(),v1.end());
sort(v2.begin(),v2.end());
int mx=0;
for (auto i:v1){
if (mx>i.y) flag=0;
mx=i.y;
}
mx=0;
for (auto i:v2){
if (mx>i.y) flag=0;
mx=i.y;
}
if (flag) cout<<"Yes\n";
else cout<<"No\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
6 ms |
588 KB |
Output is correct |
5 |
Correct |
14 ms |
1104 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
25 ms |
1564 KB |
Output is correct |
10 |
Correct |
18 ms |
3600 KB |
Output is correct |
11 |
Correct |
4 ms |
472 KB |
Output is correct |
12 |
Correct |
19 ms |
1220 KB |
Output is correct |
13 |
Correct |
27 ms |
5884 KB |
Output is correct |
14 |
Correct |
31 ms |
5920 KB |
Output is correct |
15 |
Correct |
33 ms |
5952 KB |
Output is correct |
16 |
Correct |
66 ms |
8936 KB |
Output is correct |
17 |
Correct |
28 ms |
6352 KB |
Output is correct |
18 |
Correct |
38 ms |
8904 KB |
Output is correct |
19 |
Correct |
30 ms |
6280 KB |
Output is correct |
20 |
Correct |
30 ms |
6280 KB |
Output is correct |
21 |
Correct |
29 ms |
6388 KB |
Output is correct |
22 |
Correct |
32 ms |
6344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
4 ms |
500 KB |
Output is correct |
6 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
6 ms |
588 KB |
Output is correct |
5 |
Correct |
14 ms |
1104 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
25 ms |
1564 KB |
Output is correct |
10 |
Correct |
18 ms |
3600 KB |
Output is correct |
11 |
Correct |
4 ms |
472 KB |
Output is correct |
12 |
Correct |
19 ms |
1220 KB |
Output is correct |
13 |
Correct |
27 ms |
5884 KB |
Output is correct |
14 |
Correct |
31 ms |
5920 KB |
Output is correct |
15 |
Correct |
33 ms |
5952 KB |
Output is correct |
16 |
Correct |
66 ms |
8936 KB |
Output is correct |
17 |
Correct |
28 ms |
6352 KB |
Output is correct |
18 |
Correct |
38 ms |
8904 KB |
Output is correct |
19 |
Correct |
30 ms |
6280 KB |
Output is correct |
20 |
Correct |
30 ms |
6280 KB |
Output is correct |
21 |
Correct |
29 ms |
6388 KB |
Output is correct |
22 |
Correct |
32 ms |
6344 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
328 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |