이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "friend.h"
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define  F first
#define S second
#define pb push_back
#define endl "\n"
#define sz(x) (ll)x.size()
typedef vector <ll> vi;
typedef pair <ll,ll> ii;
typedef vector <ii> vii;
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define dbg2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl;
#define dbg3(x,y,z) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<" "<<#z<<": "<<z<<endl;
void printVct(vi &v){
	cout<<"v: ";
	for (ll i =0; i<sz(v); i++){
		cout<<v[i]<<" ";
	}
	cout<<endl;
}
vector <vi> arr, adj;
ll n;
vi con, hos, pro;
vector <vi> dp;		//dp[n][2] => pos, bool (can get - cannot get)
ll dfs(ll u, ll p, bool can_get){
	ll ans_get = con[u], ans_not_get = 0;
	for (ll i =0; i<sz(adj[u]); i++){
		ll c = adj[u][i];
		if (c != p){
			ll child_can_get_ans = dfs(c,u,1);
			ll child_cannot_get_ans = dfs(c,u,0);
			if (can_get) ans_get += child_cannot_get_ans + con[u];
			ans_not_get += child_can_get_ans;
		}
	}
	if (!can_get) ans_get = 0;
	dp[u][can_get] = max(ans_get, ans_not_get);
	return dp[u][can_get];
}
int findSample(int N,int cc[],int hh[],int pp[]){
	n = N;
	for (ll i=0; i<n; i++){
		con.pb(cc[i]);
		hos.pb(hh[i]);
		pro.pb(pp[i]);
	}
	adj.assign(n,vi());
	for (ll i =1; i<n; i++){
		ll c = hos[i];
		if (pro[i] != 0){
			for (ll j = 0; j<sz(adj[c]); j++){
				ll d = adj[c][j];
				adj[d].pb(i);
				adj[i].pb(d);
			}
		}
		if (pro[i] != 1){
			adj[c].pb(i);
			adj[i].pb(c);
		}
	}
	arr.assign(n, vi(n,0));
	for (ll i =0; i<n; i++){
		for (ll j =0; j<sz(adj[i]); j++){
			arr[i][adj[i][j]] = 1;
		}
	}
	dp.assign(n, vi(2));
	ll ans = dfs(0,-1,1);
	return ans;
}
/*
3
1 1 1
0 0 0 1
6
13 3 6 20 10 15
0 0 0 1 1 2 2 1 0 0
6
13 3 6 20 10 15
0 0 0 1 1 2 2 1 0 0
*/
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |