QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#260130#4229. GCD HarmonyMeetBrahmbhattCompile Error//C++141.9kb2023-11-21 20:48:012023-11-21 20:48:02

Judging History

你现在查看的是最新测评结果

  • [2023-11-21 20:48:02]
  • 评测
  • [2023-11-21 20:48:01]
  • 提交

answer

/**
 *  - Meet Brahmbhatt
 *  - Hard work always pays off
**/
#include"bits/stdc++.h"
using namespace std;

#ifdef MeetBrahmbhatt
#include "debug.h"
#else
#define dbg(...) 72
#endif

#define endl "\n"
#define int long long

const long long INF = 4e18;

const int N = 1e4 + 10;
vector<int> pf[N];
vector<int> isp(N, 1);
vector<int> val(N, 1);

void pre() {
    isp[0] = isp[1] = 0;
    for (int i = 2; i < 100; i++) {
        if (isp[i]) {
            for (int j = i; j < N; j += i) {
                val[j] *= i;
                pf[j].push_back(i);
                if (j != i) {
                    isp[j] = 0;
                }
            }
        }
    }
}



void solve() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    vector<vector<int>> G(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector dp(n, vector<int>(100, INF));
    function<void(int, int)> dfs = [&] (int u, int par) {
        vector<int> cost(N);
        for (int to : G[u]) {
            if (to != par) {
                dfs(to, u);
                for (int i = 2; i < N; i++) {
                    int take = INF;
                    for (int x : pf[i]) {
                        take = min(take, dp[to][x]);
                    }
                    cost[i] += take;
                }
            }
        }
        for (int i = 2; i < N; i++) {
            int t = cost[i] + val[i] * (val[i] != val[v[u]]);
            for (int x : pf[i]) {
                dp[u][x] = min(dp[u][x], t);
            }
        }
    };
    dfs(0, -1);
    int ans = *min_element(dp[0].begin(), dp[0].end());
    assert(ans <= 2 * n);
    cout << ans << endl;
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    cout << fixed << setprecision(9);
    pre();
    int tt = 1;
    // cin >> tt;
    while (tt--) solve();
    return 0;
}

詳細信息

answer.code: In function ‘void solve()’:
answer.code:56:12: error: missing template arguments before ‘dp’
   56 |     vector dp(n, vector<int>(100, INF));
      |            ^~
answer.code: In lambda function:
answer.code:65:42: error: ‘dp’ was not declared in this scope
   65 |                         take = min(take, dp[to][x]);
      |                                          ^~
answer.code:74:17: error: ‘dp’ was not declared in this scope
   74 |                 dp[u][x] = min(dp[u][x], t);
      |                 ^~
answer.code: In function ‘void solve()’:
answer.code:79:28: error: ‘dp’ was not declared in this scope
   79 |     int ans = *min_element(dp[0].begin(), dp[0].end());
      |                            ^~