QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#114686#6638. TreelectionxaphoenixWA 132ms36668kbC++141.8kb2023-06-22 22:04:082023-06-22 22:04:10

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-22 22:04:10]
  • 评测
  • 测评结果:WA
  • 用时:132ms
  • 内存:36668kb
  • [2023-06-22 22:04:08]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define LC k<<1
#define RC k<<1|1
#define IO cin.sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define rep(i,a,n) for (int i = a; i < n; i++)
#define repn(i,a,n) for (int i = a; i <= n; i++)
#define per(i,a,n) for (int i = (n) - 1; i >= a; i--)
#define pern(i,a,n) for (int i = n; i >= a; i--)

typedef long long LL;
typedef long double LD;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<int, LL> PIL;
typedef pair<LL, int> PLI;
typedef pair<double, double> PDD;
typedef pair<ull, ull> PUU;
typedef pair<LL, LL> PLL;

const int N = 1100000;
const int M = 1100000;
const int mod = 1e9+7;
const int inf = (int)1e9;
const LL INF = 1e18;
const double eps = 1e-9;

mt19937_64 Rand((unsigned long long)new char);
#define rand Rand

int T, n, sz[N], lim, delta, pp[N], dp[N];
vector<int> g[N];
void dfs(int x) {
	sz[x] = 1;
	int sum = 0;
	for (auto y: g[x]) {
		dfs(y);
		sz[x] += sz[y];
		sum += dp[y];
	}
	dp[x] = max(sum - lim, 0) + 1;
}
void work(int x) {
	if (sz[x] == lim + 1) pp[x] = 1;
	for (auto y: g[x]) {
		if (dp[y] >= 1 + delta) work(y);
	}
}
int main() {
	IO;
	cin >> T;
	while (T--) {
		cin >> n;
		repn(i, 1, n) g[i].clear(), pp[i] = 0;
		repn(i, 2, n) {
			int x;
			cin >> x;
			g[x].pb(i);
		}
		int l = 1, r = n, ans;
		while (l <= r) {
			int mid = (l + r) / 2;
			lim = mid;
			dfs(1);
			if (dp[1] <= lim + 1) r = mid - 1, ans = mid;
			else l = mid + 1;
		}
		repn(i, 1, n) if (sz[i] - 1 > ans) pp[i] = 1;
		lim = ans - 1;
		dfs(1);
		delta = dp[1] - 1 - lim;
		work(1);
		repn(i, 1, n) cout << pp[i];
		cout << "\n";
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
4
1 2 3
5
1 1 2 2

output:

1100
10000

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 132ms
memory: 36668kb

input:

10
100000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 10...

output:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result:

wrong answer 1st lines differ - expected: '111111111111111111111111111111...0000000000000000000000000000000', found: '111111111111111111111111111111...0000000000000000000000000000000'