Submission #1039204

#TimeUsernameProblemLanguageResultExecution timeMemory
1039204AndreyJail (JOI22_jail)C++14
61 / 100
5051 ms32544 KiB
#include<bits/stdc++.h> using namespace std; vector<int> haha[200001]; vector<int> wow(200001); vector<int> wut(200001); vector<int> topo[200001]; bool dfs(int a, int t, int x, int p) { if(a == x) { if(wow[a] != -1 && wow[a] != p) { topo[wow[a]].push_back(p); } if(wut[a] != -1 && wut[a] != p) { topo[p].push_back(wut[a]); } return true; } for(int v: haha[a]) { if(v != t) { if(dfs(v,a,x,p)) { if(wow[a] != -1 && wow[a] != p) { topo[wow[a]].push_back(p); } if(wut[a] != -1 && wut[a] != p) { topo[p].push_back(wut[a]); } return true; } } } return false; } void solve() { int n,m,a,b; cin >> n; topo[0].clear(); vector<pair<int,int>> idk(0); for(int i = 1; i <= n; i++) { haha[i].clear(); topo[i].clear(); wow[i] = -1; wut[i] = -1; } for(int i = 0; i < n-1; i++) { cin >> a >> b; haha[a].push_back(b); haha[b].push_back(a); } cin >> m; for(int i = 0; i < m; i++) { cin >> a >> b; wow[a] = i; wut[b] = i; idk.push_back({a,b}); } for(int i = 0; i < m; i++) { dfs(idk[i].first,-1,idk[i].second,i); } vector<int> br(m); for(int i = 0; i < m; i++) { for(int v: topo[i]) { br[v]++; } } vector<int> ans(0); for(int i = 0; i < m; i++) { if(br[i] == 0) { ans.push_back(i); } } for(int i = 0; i < ans.size(); i++) { for(int v: topo[ans[i]]) { br[v]--; if(br[v] == 0) { ans.push_back(v); } } } if(ans.size() == m) { cout << "Yes\n"; } else { cout << "No\n"; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while(t--) { solve(); } return 0; }

Compilation message (stderr)

jail.cpp: In function 'void solve()':
jail.cpp:73:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |     for(int i = 0; i < ans.size(); i++) {
      |                    ~~^~~~~~~~~~~~
jail.cpp:81:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   81 |     if(ans.size() == m) {
      |        ~~~~~~~~~~~^~~~
#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...