# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1044020 | 2024-08-05T06:25:15 Z | 김은성(#11005) | Prize (CEOI22_prize) | C++17 | 483 ms | 201484 KB |
#include <bits/stdc++.h> using namespace std; vector<int> graph[1000009]; int par[1000009], level[1000009], depth[1000009], sp[21][1000009]; vector<int> vec; void dfs(int v){ vec.push_back(v); for(int u: graph[v]){ level[u] = level[v] + 1; dfs(u); } } int lca(int u, int v){ if(level[u] > level[v]) swap(u, v); int i; for(i=19; i>=0; i--){ if(level[v] - level[u] >= (1<<i)) v = sp[i][v]; } for(i=19; i>=0; i--){ if(sp[i][v] == sp[i][u]) continue; v = sp[i][v]; u = sp[i][u]; } if(u != v){ u = par[u]; v = par[v]; } return u; } int main(){ int n, k, q, t, i, root; scanf("%d %d %d %d", &n, &k, &q, &t); for(i=1; i<=n; i++) scanf("%d", &par[i]); for(i=1; i<=n; i++){ scanf("%d", &par[i]); if(par[i] == -1) root = i; else graph[par[i]].push_back(i); } dfs(root); vector<int> crit; for(i=1; i<=n; i++) sp[0][i] = par[i]; for(i=1; i<=19; i++){ for(int j=1; j<=n; j++){ sp[i][j] = (sp[i-1][j]==-1 ? -1 : sp[i-1][sp[i-1][j]]); } } for(i=0; i<k; i++){ crit.push_back(vec[i]); } for(i=0; i<k; i++) printf("%d ", crit[i]); printf("\n"); for(i=1; i<k; i++) printf("? %d %d\n", crit[0], crit[i]); printf("!\n"); fflush(stdout); for(i=1; i<k; i++){ scanf("%*d %d %*d %*d", &depth[crit[i]]); } vector<pair<int, int> > query(t); for(i=0; i<t; i++){ scanf("%d %d", &query[i].first, &query[i].second); } for(i=0; i<t; i++){ //printf("lca=%d\n", lca(query[i].first, query[i].second)); printf("%d %d\n", depth[query[i].first] + depth[query[i].second] - 2*depth[lca(query[i].first, query[i].second)], depth[query[i].first] + depth[query[i].second] - 2*depth[lca(query[i].first, query[i].second)]); } fflush(stdout); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 358 ms | 157972 KB | Output is correct |
2 | Correct | 402 ms | 156976 KB | Output is correct |
3 | Correct | 235 ms | 126908 KB | Output is correct |
4 | Correct | 237 ms | 126944 KB | Output is correct |
5 | Correct | 245 ms | 125916 KB | Output is correct |
6 | Correct | 351 ms | 133376 KB | Output is correct |
7 | Correct | 396 ms | 133760 KB | Output is correct |
8 | Correct | 329 ms | 133424 KB | Output is correct |
9 | Correct | 250 ms | 127052 KB | Output is correct |
10 | Correct | 282 ms | 127244 KB | Output is correct |
11 | Correct | 278 ms | 126720 KB | Output is correct |
12 | Correct | 307 ms | 127128 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 244 ms | 156720 KB | Execution killed with signal 13 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 183 ms | 156744 KB | Execution killed with signal 13 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 461 ms | 200092 KB | Execution killed with signal 13 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 483 ms | 201484 KB | Execution killed with signal 13 |
2 | Halted | 0 ms | 0 KB | - |