제출 #780286

#제출 시각아이디문제언어결과실행 시간메모리
780286NothingXDFriend (IOI14_friend)C++17
35 / 100
7 ms2672 KiB
#include "friend.h"
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef complex<ld> point;

void debug_out(){cerr << endl;}

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
	cout << H << ' ';
	debug_out(T...);
}

#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)

const int maxn = 1e5 + 10;

int dp[maxn][2];
vector<int> g[maxn];
void dfs(int v, int p = -1){
	for (auto u: g[v]){
		dfs(u, v);
		dp[v][1] += dp[u][0];
		dp[v][0] += max(dp[u][0], dp[u][1]);
	}
}

// Find out best sample
int findSample(int n,int w[],int p[],int t[]){
	int ans = 0;
	if (t[1] == 1){
		for (int i = 0; i < n; i++) ans += w[i];
	}
	if (t[1] == 2){
		ans = *max_element(w, w + n);
	}
	if (t[1] == 0){
		for (int i = 1; i < n; i++){
			g[p[i]].push_back(i);
		}
		for (int i = 0; i < n; i++){
			dp[i][1] = w[i];
		}
		dfs(0);
		ans = max(dp[0][0], dp[0][1]);
	}
	return ans;
}
#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...