QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#206420#6438. Crystalflywiseman123Compile Error//C++141015b2023-10-07 20:24:422023-10-07 20:24:43

Judging History

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

  • [2023-10-07 20:24:43]
  • 评测
  • [2023-10-07 20:24:42]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

vector<int>g[MAXN];
int n,u, v;
int a[MAXN];
int f[MAXN], sum[MAXN], t[MAXN];
void dfs(int u,int fa) {
	int mx = 0;
	multiset<int>st;//维护t[v] = 3的点的最大值
	for (int v : g[u]) {
		if (v == fa)continue;
		dfs(v, u);
		sum[u] += f[v];
		mx = max(mx, a[v]);//找到a[v]的最大值
		if (t[v] == 3)st.insert(a[v]);//把t[v] = 3 的点放进来
	}
	f[u] = sum[u] + mx;
	st.insert(-INF);
	for (int v : g[u]) {
		if (v == fa)continue;
		if (t[v] == 3)st.erase(st.find(a[v]));
		f[u] = max(f[u],sum[u] - f[v] + a[v] + sum[v] + *st.rbegin());
		if (t[v] == 3)st.insert(a[v]);//注意不要忘了添加回去
	}
}
void slove() {
	cin >> n;
	for (int i = 1; i <= n; i++)g[i].clear(), f[i] = sum[i] = 0;
	for (int i = 1; i <= n; i++)cin >> a[i];
	for (int i = 1; i <= n; i++)cin >> t[i];
	for (int i = 1; i <= n - 1; i++) {
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(1, 0);
	cout << f[1] + a[1] << endl;
}

Details

answer.code:4:14: error: ‘MAXN’ was not declared in this scope
    4 | vector<int>g[MAXN];
      |              ^~~~
answer.code:6:7: error: ‘MAXN’ was not declared in this scope
    6 | int a[MAXN];
      |       ^~~~
answer.code:7:7: error: ‘MAXN’ was not declared in this scope
    7 | int f[MAXN], sum[MAXN], t[MAXN];
      |       ^~~~
answer.code:7:18: error: ‘MAXN’ was not declared in this scope
    7 | int f[MAXN], sum[MAXN], t[MAXN];
      |                  ^~~~
answer.code:7:27: error: ‘MAXN’ was not declared in this scope
    7 | int f[MAXN], sum[MAXN], t[MAXN];
      |                           ^~~~
answer.code: In function ‘void dfs(int, int)’:
answer.code:11:22: error: ‘g’ was not declared in this scope
   11 |         for (int v : g[u]) {
      |                      ^
answer.code:14:17: error: ‘sum’ was not declared in this scope
   14 |                 sum[u] += f[v];
      |                 ^~~
answer.code:14:27: error: ‘f’ was not declared in this scope
   14 |                 sum[u] += f[v];
      |                           ^
answer.code:15:30: error: ‘a’ was not declared in this scope
   15 |                 mx = max(mx, a[v]);//找到a[v]的最大值
      |                              ^
answer.code:16:21: error: ‘t’ was not declared in this scope
   16 |                 if (t[v] == 3)st.insert(a[v]);//把t[v] = 3 的点放进来
      |                     ^
answer.code:18:9: error: ‘f’ was not declared in this scope
   18 |         f[u] = sum[u] + mx;
      |         ^
answer.code:18:16: error: ‘sum’ was not declared in this scope
   18 |         f[u] = sum[u] + mx;
      |                ^~~
answer.code:19:20: error: ‘INF’ was not declared in this scope
   19 |         st.insert(-INF);
      |                    ^~~
answer.code:20:22: error: ‘g’ was not declared in this scope
   20 |         for (int v : g[u]) {
      |                      ^
answer.code:22:21: error: ‘t’ was not declared in this scope
   22 |                 if (t[v] == 3)st.erase(st.find(a[v]));
      |                     ^
answer.code:22:48: error: ‘a’ was not declared in this scope
   22 |                 if (t[v] == 3)st.erase(st.find(a[v]));
      |                                                ^
answer.code:23:49: error: ‘a’ was not declared in this scope
   23 |                 f[u] = max(f[u],sum[u] - f[v] + a[v] + sum[v] + *st.rbegin());
      |                                                 ^
answer.code:24:21: error: ‘t’ was not declared in this scope
   24 |                 if (t[v] == 3)st.insert(a[v]);//注意不要忘了添加回去
      |                     ^
answer.code: In function ‘void slove()’:
answer.code:29:37: error: ‘g’ was not declared in this scope
   29 |         for (int i = 1; i <= n; i++)g[i].clear(), f[i] = sum[i] = 0;
      |                                     ^
answer.code:29:51: error: ‘f’ was not declared in this scope
   29 |         for (int i = 1; i <= n; i++)g[i].clear(), f[i] = sum[i] = 0;
      |                                                   ^
answer.code:29:58: error: ‘sum’ was not declared in this scope
   29 |         for (int i = 1; i <= n; i++)g[i].clear(), f[i] = sum[i] = 0;
      |                                                          ^~~
answer.code:30:44: error: ‘a’ was not declared in this scope
   30 |         for (int i = 1; i <= n; i++)cin >> a[i];
      |                                            ^
answer.code:31:44: error: ‘t’ was not declared in this scope
   31 |         for (int i = 1; i <= n; i++)cin >> t[i];
      |                                            ^
answer.code:34:17: error: ‘g’ was not declared in this scope
   34 |                 g[u].push_back(v);
      |                 ^
answer.code:38:17: error: ‘f’ was not declared in this scope
   38 |         cout << f[1] + a[1] << endl;
      |                 ^
answer.code:38:24: error: ‘a’ was not declared in this scope
   38 |         cout << f[1] + a[1] << endl;
      |                        ^