QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#74284#5. 在线 O(1) 逆元QingyuCompile Error//C++14761b2023-01-31 14:04:392024-11-05 21:47:20

Judging History

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

  • [2024-11-05 21:47:20]
  • 管理员手动重测本题所有提交记录
  • [2024-11-05 21:43:43]
  • 管理员手动重测本题所有提交记录
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-31 14:04:43]
  • 评测
  • [2023-01-31 14:04:39]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 50;

int n, fa[N];
int64_t f[N], g[N], cd[N][2], mx[N], su[N], siz[N];

void upd(int64_t *f, int64_t z) {
	if (f[0] < z)
		f[1] = f[0], f[0] = z;
	else if (f[1] < z)
		f[1] = z;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cin >> n;
	for (int i = 2; i <= n; ++i) {
		cin >> fa[i];
	}
	for (int i = n; i >= 1; --i) {
		++siz[i];
		siz[fa[i]] += siz[i];
	}
	for (int i = n; i >= 1; --i) {
		f[i] = su[i] + 2 * siz[i] - max(cd[i][0] + cd[i][1], 2 * mx[i]);
		g[i] = su[i] - cd[i][0] + siz[i];
		su[fa[i]] += f[i];
		upd(cd[fa[i]], f[i] + siz[i] - g[i]);
		mx[fa[i]] = max(mx[fa[i]], siz[i]);
	}
	cout << f[1] << '\n';
}

Details

implementer.cpp: In function ‘int main()’:
implementer.cpp:22:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
/usr/bin/ld: /tmp/ccVW2C1F.o: in function `main':
answer.code:(.text.startup+0x0): multiple definition of `main'; /tmp/ccImHeBE.o:implementer.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccImHeBE.o: in function `main':
implementer.cpp:(.text.startup+0x12b): undefined reference to `init(int)'
/usr/bin/ld: implementer.cpp:(.text.startup+0x1d0): undefined reference to `inv(int)'
collect2: error: ld returned 1 exit status