Submission #602500

#TimeUsernameProblemLanguageResultExecution timeMemory
602500CyberCowJail (JOI22_jail)C++17
0 / 100
9 ms3412 KiB
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <string> #include <cmath> #include <map> #include <unordered_map> #include <unordered_set> #include <fstream> #include <iomanip> #include <iterator> #include <stack> #include <deque> using namespace std; using ll = long long; vector<int> v[120005]; int ar[120005], col[120005]; vector<pair<int, int>> c; stack<int> s; int st = 0; void gum(int arj) { s.pop(); while (!s.empty()) { ar[s.top()] += arj; s.pop(); } } void Dfs(int g, int p, int kang, int gu) { if (st) return; s.push(g); if (g == kang) { gum(gu); st = 1; } if (st) return; for (auto to : v[g]) { if (to != p) Dfs(to, g, kang, gu); if (st) return; } if (st) return; s.pop(); } void solve() { int n, i, j, x, m, y, qan; cin >> n; for ( i = 0; i < n - 1; i++) { cin >> x >> y; v[x].push_back(y); v[y].push_back(x); } cin >> m; for ( i = 0; i < m; i++) { cin >> x >> y; c.push_back({ x, y }); st = 0; Dfs(x, -1, y, 1); } int ans = 1; for ( i = 0; i < m; i++) { for ( j = 0; j < m; j++) { if (ar[c[j].second] == 0 && col[j] == 0) { st = 0; Dfs(c[j].first, -1, c[j].second, -1); col[j] = 1; break; } } if (j == m) { ans = 0; break; } } if (ans) cout << "Yes\n"; else cout << "No\n"; col[0] = 0; for ( i = 1; i <= n; i++) { v[i].clear(); col[i] = 0; ar[i] = 0; } c.clear(); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int tt = 1; cin >> tt; while (tt--) { solve(); } return 0; }

Compilation message (stderr)

jail.cpp: In function 'void solve()':
jail.cpp:60:24: warning: unused variable 'qan' [-Wunused-variable]
   60 |  int n, i, j, x, m, y, qan;
      |                        ^~~
#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...