# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
631554 |
2022-08-18T08:30:55 Z |
Darren0724 |
Jail (JOI22_jail) |
C++17 |
|
76 ms |
10924 KB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define rz resize
#define pb emplace_back
#define x first
#define y second
int INF=1e18;
int mod=1e9+7;
void solve(){
int n;cin>>n;
vector<vector<int>> adj(n);
if(n>-1){
for(int i=1;i<n;i++){
int a,b;cin>>a>>b;
a--;b--;
adj[a].push_back(b);
adj[b].push_back(a);
}
int q;cin>>q;
vector<int> v1(n+1),v2(n+1);
vector<pii> v3,v4;
bool flag=0;
for(int i=0;i<q;i++){
int a,b;cin>>a>>b;
a--;b--;
if(b>a){
v1[a]++;
v1[b+1]--;
v3.push_back({a,b});
}
else{
v2[b]++;
v2[a+1]--;
v4.push_back({b,a});
}
}
for(int i=1;i<n;i++){
v1[i]+=v1[i-1];
v2[i]+=v2[i-1];
}
for(int i=0;i<n;i++){
if(v1[i]>0&&v2[i]>0){
flag=1;
}
}
sort(all(v3));
sort(all(v4),greater<pii>());
int a=-INF;
for(auto p:v3){
if(a>p.second){
flag=1;
}
a=p.second;
}
a=INF;
for(auto p:v4){
if(a<p.second){
flag=1;
}
a=p.second;
}
cout<<(flag?"No":"Yes")<<'\n';
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int t=1;
cin>>t;
while(t--){
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
12 ms |
324 KB |
Output is correct |
5 |
Correct |
27 ms |
328 KB |
Output is correct |
6 |
Correct |
2 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
28 ms |
768 KB |
Output is correct |
10 |
Correct |
35 ms |
8788 KB |
Output is correct |
11 |
Correct |
8 ms |
212 KB |
Output is correct |
12 |
Correct |
31 ms |
332 KB |
Output is correct |
13 |
Correct |
38 ms |
9880 KB |
Output is correct |
14 |
Correct |
40 ms |
9932 KB |
Output is correct |
15 |
Correct |
41 ms |
9624 KB |
Output is correct |
16 |
Correct |
76 ms |
10704 KB |
Output is correct |
17 |
Correct |
45 ms |
9924 KB |
Output is correct |
18 |
Correct |
57 ms |
10924 KB |
Output is correct |
19 |
Correct |
45 ms |
9924 KB |
Output is correct |
20 |
Correct |
45 ms |
9908 KB |
Output is correct |
21 |
Correct |
41 ms |
9844 KB |
Output is correct |
22 |
Correct |
41 ms |
9924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
260 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
3 ms |
212 KB |
Output is correct |
4 |
Incorrect |
2 ms |
344 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
260 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
3 ms |
212 KB |
Output is correct |
4 |
Incorrect |
2 ms |
344 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
260 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
3 ms |
212 KB |
Output is correct |
4 |
Incorrect |
2 ms |
344 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
260 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
3 ms |
212 KB |
Output is correct |
4 |
Incorrect |
2 ms |
344 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
6 ms |
212 KB |
Output is correct |
6 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
12 ms |
324 KB |
Output is correct |
5 |
Correct |
27 ms |
328 KB |
Output is correct |
6 |
Correct |
2 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
28 ms |
768 KB |
Output is correct |
10 |
Correct |
35 ms |
8788 KB |
Output is correct |
11 |
Correct |
8 ms |
212 KB |
Output is correct |
12 |
Correct |
31 ms |
332 KB |
Output is correct |
13 |
Correct |
38 ms |
9880 KB |
Output is correct |
14 |
Correct |
40 ms |
9932 KB |
Output is correct |
15 |
Correct |
41 ms |
9624 KB |
Output is correct |
16 |
Correct |
76 ms |
10704 KB |
Output is correct |
17 |
Correct |
45 ms |
9924 KB |
Output is correct |
18 |
Correct |
57 ms |
10924 KB |
Output is correct |
19 |
Correct |
45 ms |
9924 KB |
Output is correct |
20 |
Correct |
45 ms |
9908 KB |
Output is correct |
21 |
Correct |
41 ms |
9844 KB |
Output is correct |
22 |
Correct |
41 ms |
9924 KB |
Output is correct |
23 |
Correct |
0 ms |
260 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
3 ms |
212 KB |
Output is correct |
26 |
Incorrect |
2 ms |
344 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |