Submission #632459

# Submission time Handle Problem Language Result Execution time Memory
632459 2022-08-20T05:37:04 Z Mahdi Jail (JOI22_jail) C++17
0 / 100
1 ms 212 KB
    #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 time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -