QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#309756#8134. LCA Countingucup-team1303#WA 1ms5632kbC++201.6kb2024-01-20 20:28:242024-01-20 20:28:25

Judging History

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

  • [2024-01-20 20:28:25]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5632kb
  • [2024-01-20 20:28:24]
  • 提交

answer

// MagicDark
#include <bits/stdc++.h>
#define debug cerr << "[" << __LINE__ << "] "
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> inline void chkmax(T& x, T y) {x = max(x, y);}
template <typename T> inline void chkmin(T& x, T y) {x = min(x, y);}
template <typename T> inline void read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	x *= f;
}
const int N = 2e5 + 10;
int n, f[N], s, g[N];
vector <int> v[N];
void dfs(int x) {
	if (v[x].empty()) {
		f[x] = 1;
		s++;
		return;
	}
	int mx1 = 0, mx2 = 0, c = 0;
	for (int i: v[x]) {
		dfs(i);
		if (v[i].size() > 1) c++;
		g[x] += g[i];
		if (f[i] > mx1) mx2 = mx1, mx1 = f[i];
		else chkmax(mx2, f[i]);
	}
	f[x] = mx1 + mx2;
	g[x] += max(0, c - 2);
	// if (v[x].size() > 1) g[x] += v[x].size() - 2;
}
signed main() {
	read(n);
	F(i, 2, n) {
		int x;
		read(x);
		v[x].push_back(i);
	}
	dfs(1);
	// debug << f[1] << endl;
	F(i, 1, f[1]) {
		// if (i <= f[1]) 
		cout << 2 * i - 1 << ' ';
		// else cout << 2 * f[1] - 1 + i - f[1] << ' ';
	}
	// debug << f[1] << endl;
	int res = 0, ans = f[1] - 1;
	F(i, f[1] + 1, s) {
		res++;
		if (res == 2) {
			res = 0;
			ans++;
		}
		cout << i + min(g[1] + f[1], ans) << ' ';
	}
	return 0;
}
/* why?
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3592kb

input:

7
1 1 2 4 2 2

output:

1 3 5 6 

result:

ok 4 number(s): "1 3 5 6"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 5632kb

input:

10
1 1 2 2 1 1 1 2 4

output:

1 3 5 6 8 9 10 

result:

wrong answer 5th numbers differ - expected: '7', found: '8'