Submission #632459

#TimeUsernameProblemLanguageResultExecution timeMemory
632459MahdiJail (JOI22_jail)C++17
0 / 100
1 ms212 KiB
#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]; void sol(){ cin>>n; for(int i=1;i<n;++i){ int u, v; cin>>u>>v; } priority_queue<pii>pq, qp; cin>>m; for(int i=0;i<m;++i){ int u, v; cin>>u>>v; if(u<v) pq.push({-u+1, v}); else qp.push({-v+1, u}); } memset(a, -1, 4*n); int r1=0, r2=0; for(int i=0;i<n;++i){ while(!pq.empty() && -pq.top().F<=i){ if(pq.top().S<=r1){ cout<<"NO\n"; return; } r1=pq.top().S; pq.pop(); } while(!qp.empty() && -qp.top().F<=i){ if(qp.top().S<=r2){ cout<<"NO\n"; return; } r2=qp.top().S; qp.pop(); } if(r1>i) a[i]=0; if(r2>i){ if(a[i]==0){ cout<<"NO\n"; return; } a[i]=1; } } cout<<"YES\n"; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int T; cin>>T; while(T--) sol(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...