Submission #208294

#TimeUsernameProblemLanguageResultExecution timeMemory
208294SortingFriend (IOI14_friend)C++14
19 / 100
6 ms508 KiB
#include "friend.h"
#include <bits/stdc++.h>

using namespace std;

const int kN = 1007;

vector<int> adj[kN];
pair<int, bool> dp[kN][2];

int solve(int u, bool can, int parent, int confidence[]){
	if(dp[u][can].second)
		return dp[u][can].first;

	dp[u][can].second = true;
	int &ans = dp[u][can].first;
	ans = 0;

	if(can){
		int curr_ans = confidence[u];
		for(int to: adj[u]){
			if(to == parent)
				continue;

			curr_ans += solve(to, false, u, confidence);
		}
		ans = max(ans, curr_ans);
	}

	int curr_ans = 0;
	for(int to: adj[u]){
		if(to == parent)
			continue;

		curr_ans += solve(to, true, u, confidence);
	}
	ans = max(ans, curr_ans);

	return ans;
}

int findSample(int n, int confidence[], int host[], int protocol[]){
	for(int i = 1; i < n; ++i){
		adj[host[i]].push_back(i);
		adj[i].push_back(host[i]);
	}

	return solve(0, true, -1, confidence);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...