QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#269489#7684. Sweet SugarAshokaCompile Error//C++202.4kb2023-11-29 17:37:592023-11-29 17:37:59

Judging History

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

  • [2023-11-29 17:37:59]
  • 评测
  • [2023-11-29 17:37:59]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

constexpr i64 inf = 1E18;

void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> c(n);
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  vector<vector<int>> adj(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    --u; --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }

  vector dp(n, array<i64, 2> ({-inf, -inf}));
  i64 ans = 0;
  auto dfs = [&](auto self, int u, int fa) -> void {
    dp[u][c[u] & 1] = c[u];
    for (auto v : adj[u]) {
      if (v == fa) continue;
      self(self, v, u);
      array<i64, 2> tmp = {-inf, -inf};
      for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
          tmp[i ^ j] = max(tmp[i ^ j], dp[u][i] + dp[v][j]);
        }
      }
      dp[u] = tmp;
    }
    if (dp[u][k & 1] >= k) {
      ans += 1;
      dp[u] = {0, -inf};
    }
    dp[u][0] = max(dp[u][0], 0LL);
    return ;
  };

  dfs(dfs, 0, -1);
  if (dp[0][k & 1] >= k) ++ans;
  cout << ans << "\n";
  return ;
} 

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    solve();
  } 
  return 0;
}#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

constexpr i64 inf = 1E18;

void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> c(n);
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  vector<vector<int>> adj(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    --u; --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }

  vector dp(n, array<i64, 2> ({-inf, -inf}));
  i64 ans = 0;
  auto dfs = [&](auto self, int u, int fa) -> void {
    dp[u][c[u] & 1] = c[u];
    for (auto v : adj[u]) {
      if (v == fa) continue;
      self(self, v, u);
      array<i64, 2> tmp = {-inf, -inf};
      for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
          tmp[i ^ j] = max(tmp[i ^ j], dp[u][i] + dp[v][j]);
        }
      }
      dp[u] = tmp;
    }
    if (dp[u][k & 1] >= k) {
      ans += 1;
      dp[u] = {0, -inf};
    }
    dp[u][0] = max(dp[u][0], 0LL);
    return ;
  };

  dfs(dfs, 0, -1);
  if (dp[0][k & 1] >= k) ++ans;
  cout << ans << "\n";
  return ;
} 

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    solve();
  } 
  return 0;
}

Details

answer.code:62:2: error: stray ‘#’ in program
   62 | }#include <bits/stdc++.h>
      |  ^
answer.code:62:12: error: ‘bits’ was not declared in this scope
   62 | }#include <bits/stdc++.h>
      |            ^~~~
answer.code:62:17: error: ‘stdc’ was not declared in this scope; did you mean ‘std’?
   62 | }#include <bits/stdc++.h>
      |                 ^~~~
      |                 std
answer.code:62:12: error: ‘bits’ was not declared in this scope
   62 | }#include <bits/stdc++.h>
      |            ^~~~
answer.code:62:17: error: ‘stdc’ was not declared in this scope; did you mean ‘std’?
   62 | }#include <bits/stdc++.h>
      |                 ^~~~
      |                 std
answer.code:62:12: error: ‘bits’ was not declared in this scope
   62 | }#include <bits/stdc++.h>
      |            ^~~~
answer.code:62:17: error: ‘stdc’ was not declared in this scope; did you mean ‘std’?
   62 | }#include <bits/stdc++.h>
      |                 ^~~~
      |                 std
answer.code:62:12: error: ‘bits’ was not declared in this scope
   62 | }#include <bits/stdc++.h>
      |            ^~~~
answer.code:62:17: error: ‘stdc’ was not declared in this scope; did you mean ‘std’?
   62 | }#include <bits/stdc++.h>
      |                 ^~~~
      |                 std
answer.code:62:12: error: ‘bits’ was not declared in this scope
   62 | }#include <bits/stdc++.h>
      |            ^~~~
answer.code:62:17: error: ‘stdc’ was not declared in this scope; did you mean ‘std’?
   62 | }#include <bits/stdc++.h>
      |                 ^~~~
      |                 std
answer.code:62:12: error: ‘bits’ was not declared in this scope
   62 | }#include <bits/stdc++.h>
      |            ^~~~
answer.code:62:17: error: ‘stdc’ was not declared in this scope; did you mean ‘std’?
   62 | }#include <bits/stdc++.h>
      |                 ^~~~
      |                 std
answer.code:62:12: error: ‘bits’ was not declared in this scope
   62 | }#include <bits/stdc++.h>
      |            ^~~~
answer.code:62:17: error: ‘stdc’ was not declared in this scope; did you mean ‘std’?
   62 | }#include <bits/stdc++.h>
      |                 ^~~~
      |                 std
answer.code:62:12: error: ‘bits’ was not declared in this scope
   62 | }#include <bits/stdc++.h>
      |            ^~~~
answer.code:62:17: error: ‘stdc’ was not declared in this scope; did you mean ‘std’?
   62 | }#include <bits/stdc++.h>
      |                 ^~~~
      |                 std
answer.code:62:12: error: ‘bits’ was not declared in this scope
   62 | }#include <bits/stdc++.h>
      |            ^~~~
answer.code:62:17: error: ‘stdc’ was not declared in this scope; did you mean ‘std’?
   62 | }#include <bits/stdc++.h>
      |                 ^~~~
      |                 std
answer.code:62:3: error: ‘include’ does not name a type
   62 | }#include <bits/stdc++.h>
      |   ^~~~~~~
answer.code:67:15: error: redefinition of ‘constexpr const i64 inf’
   67 | constexpr i64 inf = 1E18;
      |               ^~~
answer.code:6:15: note: ‘constexpr const i64 inf’ previously defined here
    6 | constexpr i64 inf = 1E18;
      |               ^~~
answer.code:69:6: error: redefinition of ‘void solve()’
   69 | void solve() {
      |      ^~~~~
answer.code:8:6: note: ‘void solve()’ previously defined here
    8 | void solve() {
      |      ^~~~~
answer.code:114:5: error: redefinition of ‘int main()’
  114 | int main() {
      |     ^~~~
answer.code:53:5: note: ‘int main()’ previously defined here
   53 | int main() {
      |     ^~~~