답안 #791542

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
791542 2023-07-24T07:16:40 Z t6twotwo Prize (CEOI22_prize) C++17
컴파일 오류
0 ms 0 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);
        }
    };
    choose(choose, root);
    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];
    };
    vector<pair<int, int>> queries(T);
    for (int i = 0; i < T; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        queries[i] = {x, y};
    }
    for (auto [x, y] : queries) {
        cout << w[x] + w[y] - 2 * w[lca(x, y)] << endl;
    }
    return 6/22;
}

Compilation message

Main.cpp:1:2: error: stray '#' in program
    1 | -#include <bits/stdc++.h>
      |  ^
Main.cpp:1:1: error: expected unqualified-id before '-' token
    1 | -#include <bits/stdc++.h>
      | ^
Main.cpp: In function 'int main()':
Main.cpp:5:5: error: 'ios' has not been declared
    5 |     ios::sync_with_stdio(false);
      |     ^~~
Main.cpp:6:5: error: 'cin' was not declared in this scope
    6 |     cin.tie(nullptr);
      |     ^~~
Main.cpp:9:5: error: 'vector' was not declared in this scope
    9 |     vector<int> p(N);
      |     ^~~~~~
Main.cpp:9:12: error: expected primary-expression before 'int'
    9 |     vector<int> p(N);
      |            ^~~
Main.cpp:10:19: error: 'p' was not declared in this scope
   10 |     for (int &x : p) {
      |                   ^
Main.cpp:13:19: error: expected primary-expression before 'int'
   13 |     vector<vector<int>> adj(N);
      |                   ^~~
Main.cpp:16:16: error: 'p' was not declared in this scope
   16 |         cin >> p[i];
      |                ^
Main.cpp:21:13: error: 'adj' was not declared in this scope
   21 |             adj[p[i]].push_back(i);
      |             ^~~
Main.cpp:24:12: error: expected primary-expression before 'int'
   24 |     vector<int> ch;
      |            ^~~
Main.cpp: In lambda function:
Main.cpp:26:13: error: 'ch' was not declared in this scope
   26 |         if (ch.size() < K) {
      |             ^~
Main.cpp:29:22: error: 'adj' was not declared in this scope
   29 |         for (int y : adj[x]) {
      |                      ^~~
Main.cpp: In function 'int main()':
Main.cpp:34:18: error: 'ch' was not declared in this scope
   34 |     for (int x : ch) {
      |                  ^~
Main.cpp:35:9: error: 'cout' was not declared in this scope
   35 |         cout << x + 1 << " ";
      |         ^~~~
Main.cpp:37:5: error: 'cout' was not declared in this scope
   37 |     cout << endl;
      |     ^~~~
Main.cpp:37:13: error: 'endl' was not declared in this scope
   37 |     cout << endl;
      |             ^~~~
Main.cpp:38:14: error: expected primary-expression before '>' token
   38 |     vector<ll> w(N);
      |              ^
Main.cpp:38:16: error: 'w' was not declared in this scope
   38 |     vector<ll> w(N);
      |                ^
Main.cpp:39:18: error: 'ch' was not declared in this scope
   39 |     for (int x : ch) {
      |                  ^~
Main.cpp:41:29: error: 'p' was not declared in this scope
   41 |             cout << "? " << p[x] + 1 << " " << x + 1 << endl;
      |                             ^
Main.cpp:45:18: error: 'ch' was not declared in this scope
   45 |     for (int x : ch) {
      |                  ^~
Main.cpp:50:12: error: expected primary-expression before 'int'
   50 |     vector<int> dep(N);
      |            ^~~
Main.cpp:51:11: error: expected ';' before 'par'
   51 |     vector par(N, vector<int>(19, -1));
      |           ^~~~
      |           ;
Main.cpp: In lambda function:
Main.cpp:53:35: error: 'par' was not declared in this scope
   53 |         for (int i = 0; i < 18 && par[x][i] != -1; i++) {
      |                                   ^~~
Main.cpp:56:22: error: 'adj' was not declared in this scope
   56 |         for (int y : adj[x]) {
      |                      ^~~
Main.cpp:58:13: error: 'par' was not declared in this scope
   58 |             par[y][0] = x;
      |             ^~~
Main.cpp:59:13: error: 'dep' was not declared in this scope
   59 |             dep[y] = dep[x] + 1;
      |             ^~~
Main.cpp: In lambda function:
Main.cpp:65:13: error: 'dep' was not declared in this scope
   65 |         if (dep[x] < dep[y]) {
      |             ^~~
Main.cpp:66:13: error: 'swap' was not declared in this scope
   66 |             swap(x, y);
      |             ^~~~
Main.cpp:69:18: error: 'dep' was not declared in this scope
   69 |             if ((dep[x] - dep[y]) >> i & 1) {
      |                  ^~~
Main.cpp:70:21: error: 'par' was not declared in this scope
   70 |                 x = par[x][i];
      |                     ^~~
Main.cpp:77:17: error: 'par' was not declared in this scope
   77 |             if (par[x][i] != par[y][i]) {
      |                 ^~~
Main.cpp:82:16: error: 'par' was not declared in this scope
   82 |         return par[x][0];
      |                ^~~
Main.cpp: In function 'int main()':
Main.cpp:84:12: error: 'pair' was not declared in this scope
   84 |     vector<pair<int, int>> queries(T);
      |            ^~~~
Main.cpp:84:17: error: expected primary-expression before 'int'
   84 |     vector<pair<int, int>> queries(T);
      |                 ^~~
Main.cpp:89:9: error: 'queries' was not declared in this scope
   89 |         queries[i] = {x, y};
      |         ^~~~~~~
Main.cpp:91:24: error: 'queries' was not declared in this scope
   91 |     for (auto [x, y] : queries) {
      |                        ^~~~~~~