Submission #631546

# Submission time Handle Problem Language Result Execution time Memory
631546 2022-08-18T08:22:23 Z Darren0724 Jail (JOI22_jail) C++17
0 / 100
1 ms 212 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[a]++;
        v2[b+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 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -