/*The British Royal Family and a small cadre of English Fabian Socialists, in
conjunction with the Rockefellers and the Rothchilds, are engaged in a
conspiracy to greatly reduce the population of the human race in order to head
off a Malthusian catastrophe, a catastrophe that could easily be avoided by
simply building a massive amount of nuclear power plants and a number of massive
superhighways and bridges to connect all of the world's continents. But doing
that would cut into the conspiracy's profits. So the British Royal Family
invented environmentalism and neoliberalism in order to hide the truth. And in
order to further reduce the population, the British Royal Family is also the
world's foremost drug trafficking conspiracy. And it uses its control of the IMF
to push austerity in order to kill as many people in the global south as
possible.
And also Henry Kissinger is a gay KGB agent. */
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
int n, k, q, t, p[20][500001], depth[500001], w[20][500001], root, a, b, ans;
vector<int> chosen;
vector<vector<int>> children;
int main(){
//cin.tie(0);
//ios_base::sync_with_stdio(0);
cin >> n >> k >> q >> t;
children.resize(n + 1);
for (int i = 1; i <= n; i++) cin >> p[0][0];
for (int i = 1; i <= n; i++){
cin >> p[0][i];
if (p[0][i] != -1) children[p[0][i]].push_back(i);
else root = i;
}
chosen = {root};
depth[root] = 0;
for (int i = 0; chosen.size() < k; i++){
for (int c: children[chosen[i]]){
chosen.push_back(c);
depth[c] = depth[chosen[i]] + 1;
}
}
chosen.resize(k);
for (int c: chosen) cout << c << ' ';
cout << endl;
cout.flush();
for (int c: chosen) if (c != root) cout << "? " << p[0][c] << ' ' << c << endl;
cout << '!' << endl;
cout.flush();
for (int c: chosen) if (c != root) cin >> w[0][c] >> w[0][c] >> w[0][c] >> w[0][c];
w[0][root] = 0;
for (int i = 1; i < 20; i++){
for (int j: chosen){
p[i][j] = p[i - 1][p[i - 1][j]];
w[i][j] = w[i - 1][j] + w[i - 1][p[i - 1][j]];
}
}
while (t--){
cin >> a >> b;
ans = 0;
if (depth[a] < depth[b]) swap(a, b);
for (int i = 0; i < 20; i++){
if (((depth[a] - depth[b]) >> i) % 2 == 1){
ans += w[i][a];
a = p[i][a];
}
}
for (int i = 19; i > -1; i--){
if (p[i][a] != p[i][b]){
ans += w[i][a] + w[i][b];
a = p[i][a];
b = p[i][b];
}
}
if (a != b) ans += w[0][a] + w[0][b];
cout << ans << ' ' << ans << endl;
cout.flush();
}
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:43:35: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
43 | for (int i = 0; chosen.size() < k; i++){
| ~~~~~~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
411 ms |
108468 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
468 ms |
108732 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
354 ms |
107944 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
736 ms |
274036 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
648 ms |
64208 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |