Submission #882224

#TimeUsernameProblemLanguageResultExecution timeMemory
882224RaresFelixJail (JOI22_jail)C++17
0 / 100
5 ms600 KiB
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; int main() { cin.tie(0); ios_base::sync_with_stdio(0); int te; cin >> te; while(te--) { int n; cin >> n; for(int i = 1; i < n; ++i) { int a, b; cin >> a >> b; } int m; cin >> m; vi S(m), T(m); vector<vi> Ev(n); for(int i = 0; i < m; ++i) { int s, t; cin >> s >> t; --s; --t; S[i] = s; T[i] = t; Ev[min(s, t)].push_back(i); Ev[max(s, t)].push_back(-i - 1); } int nr1 = 0, nr2 = 0, ok = 1; for(int i = 0; i < n; ++i) { for(auto it : Ev[i]) { if(it >= 0) { if(S[it] < T[it]) ++nr1; else ++nr2; } } if(nr1 && nr2) ok = 0; for(auto it : Ev[i]) { if(it < 0) { int i = -it - 1; if(S[i] < T[i]) --nr1; else --nr2; } } } if(ok) cout << "Yes\n"; else cout << "No\n"; } return 0; }
#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...