Submission #721125

#TimeUsernameProblemLanguageResultExecution timeMemory
721125saayan007Jail (JOI22_jail)C++17
0 / 100
3 ms3156 KiB
#include "bits/stdc++.h" using namespace std; #define int long long #define fr first #define sc second #define eb emplace_back #define nl "\n" const int N = 120001; int n, m; vector<int> adj[N]; int s[N], t[N]; int from[N]; int use[N]; void dfs(int cur, int par) { from[cur] = par; for(auto u : adj[cur]) { if(u != par) dfs(u, cur); } } void mod(int a, int b, int v = 1) { dfs(a, 0); while(b != 0) { use[b] += v; b = from[b]; } } void solve() { cin >> n; for(int i = 1; i <= n; ++i) { use[i] = 0; adj[i].clear(); } for(int i = 1; i < n; ++i) { int a, b; cin >> a >> b; adj[a].eb(b); adj[b].eb(a); } cin >> m; for(int i = 1; i <= m; ++i) { cin >> s[i] >> t[i]; } int o[m + 1]; for(int i = 1; i <= m; ++i) o[i] = i; sort(o + 1, o + m + 1, [&](int l, int r){ return make_pair(s[l], t[l]) < make_pair(s[r], t[r]); }); for(int i = 1; i < m; ++i) { int j = o[i], k = o[i + 1]; if(s[k] < t[j]) { cout << "No" << nl; return; } } cout << "Yes" << nl; } signed main() { ios::sync_with_stdio(0); cin.tie(0); int t = 1; cin >> t; for(int i = 1; i <= t; ++i) { /* cout << "Case #" << i << nl; */ solve(); /* cout << nl; */ } }
#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...