제출 #584806

#제출 시각아이디문제언어결과실행 시간메모리
584806jack715친구 (IOI14_friend)C++14
19 / 100
40 ms65536 KiB
#include "friend.h"
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pp pop_back
#define mp make_pair
#define bb back
#define ff first
#define ss second

using namespace std; 

// Find out best sample

vector<int> par, conf;
vector<vector<int> > dp, path;

int run(int indx, int state) {
    if (dp[indx][state] != -1) return dp[indx][state];
    int ret = 0;
    for (int next : path[indx]) {
        if (next == par[indx]) continue;
        par[next] = indx;
        if (state) ret += run(next, 1-state);
        else ret += max(run(next, 1-state), run(next, state));
    } 
    if (state) ret += conf[indx];
    return dp[indx][state] = ret;
}

int findSample(int n,int confidence[],int host[],int protocol[]){
    par.resize(n, -1);
    dp.resize(n, {-1, -1});
    path.resize(n), conf.resize(n);
    for (int i = 0; i < n; i++) conf[i] = confidence[i];

	for (int i = 1; i < n; i++) {
		if (protocol[i] == 0) {
			path[i].pb(host[i]);
			path[host[i]].pb(i);
		} else if (protocol[i] == 1) {
			for (int con : path[host[i]]) {
				path[i].pb(con);
				path[con].pb(i);
			}
		} else {
			for (int con : path[host[i]]) {
				path[i].pb(con);
				path[con].pb(i);
			}
			path[i].pb(host[i]);
			path[host[i]].pb(i);
		}
	}

    return max(run(0, 1), run(0, 0));
}
#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...