제출 #1000521

#제출 시각아이디문제언어결과실행 시간메모리
1000521LucaLucaMTourism (JOI23_tourism)C++17
5 / 100
5075 ms17868 KiB
#include <iostream> #include <vector> #include <algorithm> #include <cassert> #include <cstring> #warning That's the baby, that's not my baby typedef long long ll; const int NMAX = 100'000; const int LGMAX = 18; std::vector<int> g[NMAX + 1]; int parent[NMAX + 1]; int tin[NMAX + 1], tout[NMAX + 1], timer; int jump[LGMAX + 1][NMAX + 1]; void dfs(int u) { tin[u] = ++timer; for (const auto &v : g[u]) { if (v != parent[u]) { parent[v] = u; dfs(v); } } tout[u] = ++timer; } bool ancestor(int u, int v) { return tin[u] <= tin[v] && tout[v] <= tout[u]; } int lca(int u, int v) { if (ancestor(u, v)) { return u; } for (int k = LGMAX; k >= 0; k--) { if (jump[k][u] != 0 && !ancestor(jump[k][u], v)) { u = jump[k][u]; } } return jump[0][u]; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); int n, m, q; std::cin >> n >> m >> q; for (int i = 1; i < n; i++) { int u, v; std::cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } dfs(1); for (int i = 1; i <= n; i++) { jump[0][i] = parent[i]; } for (int j = 1; j <= LGMAX; j++) { for (int i = 1; i <= n; i++) { jump[j][i] = jump[j - 1][jump[j - 1][i]]; } } std::vector<int> a(m); for (auto &x : a) { std::cin >> x; } a.insert(a.begin(), 0); while (q--) { int l, r; std::cin >> l >> r; std::vector<bool> vis(n + 1, false); std::vector<int> nodes; for (int i = l; i <= r; i++) { nodes.push_back(a[i]); } std::sort(nodes.begin(), nodes.end(), [&](int x, int y) { return tin[x] < tin[y]; }); int w = -1; for (const auto &node : nodes) { if (w == -1) { w = node; } else { while (!ancestor(w, node)) { vis[w] = true; w = parent[w]; } } int u = node; while (u != w) { vis[u] = true; u = parent[u]; } assert(u == w); vis[u] = true; } std::cout << std::count(vis.begin(), vis.end(), true) << '\n'; } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

tourism.cpp:6:2: warning: #warning That's the baby, that's not my baby [-Wcpp]
    6 | #warning That's the baby, that's not my baby
      |  ^~~~~~~
#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...