# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
791517 | 2023-07-24T07:08:31 Z | t6twotwo | Prize (CEOI22_prize) | C++17 | 2059 ms | 245296 KB |
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, K, Q, T; cin >> N >> K >> Q >> T; vector<int> p(N); for (int &x : p) { cin >> x; } vector<vector<int>> adj(N); int root = -1; for (int i = 0; i < N; i++) { cin >> p[i]; if (p[i] == -1) { root = i; } else { p[i]--; adj[p[i]].push_back(i); } } vector<int> ch; auto choose = [&](auto f, int x) -> void { if (ch.size() < K) { ch.push_back(x); } for (int y : adj[x]) { f(f, y); } }; assert(root != -1); choose(choose, root); assert(ch.size() == K); for (int x : ch) { cout << x + 1 << " "; } cout << endl; vector<ll> w(N); for (int x : ch) { if (x != root) { cout << "? " << p[x] + 1 << " " << x + 1 << endl; } } cout << "!" << endl; for (int x : ch) { if (x != root) { cin >> w[x] >> w[x] >> w[x] >> w[x]; } } vector<int> dep(N); vector par(N, vector<int>(19, -1)); auto dfs = [&](auto dfs, int x) -> void { for (int i = 0; i < 18 && par[x][i] != -1; i++) { par[x][i + 1] = par[par[x][i]][i]; } for (int y : adj[x]) { w[y] += w[x]; par[y][0] = x; dep[y] = dep[x] + 1; dfs(dfs, y); } }; dfs(dfs, root); auto lca = [&](int x, int y) { if (dep[x] < dep[y]) { swap(x, y); } for (int i = 0; i < 19; i++) { if ((dep[x] - dep[y]) >> i & 1) { x = par[x][i]; } } if (x == y) { return x; } for (int i = 18; i >= 0; i--) { if (par[x][i] != par[y][i]) { x = par[x][i]; y = par[y][i]; } } return par[x][0]; }; for (int i = 0; i < T; i++) { int x, y; cin >> x >> y; x--, y--; cout << w[x] + w[y] - 2 * w[lca(x, y)] << endl; } return 6/22; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 995 ms | 122920 KB | Time limit exceeded (wall clock) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 914 ms | 123144 KB | Time limit exceeded (wall clock) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 779 ms | 122664 KB | Time limit exceeded (wall clock) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1773 ms | 244980 KB | Time limit exceeded (wall clock) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2059 ms | 245296 KB | Time limit exceeded (wall clock) |
2 | Halted | 0 ms | 0 KB | - |