Submission #994230

#TimeUsernameProblemLanguageResultExecution timeMemory
994230zsomborJail (JOI22_jail)C++17
0 / 100
2 ms5724 KiB
#include <iostream> #include <vector> using namespace std; int n, m, sz, c; bool ans; vector <vector <int>> g(2e5); vector <int> to(2e5, 0); vector <bool> del(2e5); void reset() { ans = true; for (int i = 1; i <= n; i++) { g[i].clear(); to[i] = 0; del[i] = false; } } int get_c(int x) { if (del[x]) return 0; del[x] = true; int mx = 0, sum = 1; for (int i : g[x]) { } return sum; } void cd(int x) { sz = get_c(x); get_c(x); } bool dfs(int x, int y) { if (del[x] || to[x]) return false; if (x == y) return true; del[x] = true; bool ret = false; for (int i : g[x]) if (dfs(i, y)) ret = true; del[x] = false; return ret; } bool bt() { bool kesz = true; for (int i = 1; i <= n; i++) if (to[i] && to[i] != i) kesz = false; if (kesz) return true; for (int i = 1; i <= n; i++) { if (!to[i] || to[i] == i) continue; int a = to[i]; to[i] = 0; bool jo = dfs(i, a); to[i] = a; if (!jo) continue; swap(to[i], to[a]); if (bt()) return true; swap(to[i], to[a]); } return false; } void solve() { cin >> n; reset(); int a, b; for (int i = 0; i < n - 1; i++) { cin >> a >> b; g[a].push_back(b); g[b].push_back(a); } cin >> m; for (int i = 0; i < m; i++) { cin >> a >> b; to[a] = b; } cout << (bt() ? "YES\n" : "NO\n"); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) solve(); }

Compilation message (stderr)

jail.cpp: In function 'int get_c(int)':
jail.cpp:24:11: warning: unused variable 'i' [-Wunused-variable]
   24 |  for (int i : g[x]) {
      |           ^
jail.cpp:23:6: warning: unused variable 'mx' [-Wunused-variable]
   23 |  int mx = 0, sum = 1;
      |      ^~
#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...