# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
632463 | Mahdi | Jail (JOI22_jail) | C++17 | 1 ms | 212 KiB |
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>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(v) v.begin(), v.end()
#define F first
#define S second
typedef pair<int, int> pii;
typedef long long ll;
const int N=12e4+5;
int n, m, a[N];
vector<pii>b, c;
void sol(){
cin>>n;
for(int i=1;i<n;++i){
int u, v;
cin>>u>>v;
}
cin>>m;
b.clear();
c.clear();
fill(a, a+n, -1);
bool th=1;
for(int i=0;i<m;++i){
int u, v;
cin>>u>>v;
if(u<v){
for(int j=u;j<v;++j){
if(a[j]==1)
th=0;
a[j]=0;
}
b.push_back({u, v});
}
else{
for(int j=v;j<u;++j){
if(a[j]==0)
th=0;
a[j]=1;
}
c.push_back({v, u});
}
}
sort(all(b));
sort(all(c));
for(int i=0;i+1<b.size();++i){
if(b[i].S>b[i+1].S)
th=0;
}
for(int i=0;i+1<c.size();++i){
if(c[i].S>c[i+1].S)
th=0;
}
if(th)
cout<<"YES\n";
else
cout<<"NO\n";
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int T;
cin>>T;
while(T--)
sol();
}
Compilation message (stderr)
# | 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... |