제출 #603859

#제출 시각아이디문제언어결과실행 시간메모리
6038598e7친구 (IOI14_friend)C++17
11 / 100
1088 ms4004 KiB
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r){
	while (l != r)cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 1005
#define pii pair<int, int>
#define ff first
#define ss second
#include "friend.h"

// Find out best sample
vector<int> adj[maxn];

int dp[maxn][2], wei[maxn];
/*
bool vis[maxn];
void dfs(int n, int par) {
	vis[n] = 1;
	for (int v:adj[n]) {
		if (!vis[v]) {
			dfs(v, n);
			dp[n][0] += max(dp[v][1], dp[v][0]);	
			dp[n][1] += dp[v][0];
		}
	}
	dp[n][1] += wei[n];	
}
*/
int findSample(int n,int C[],int h[],int type[]){
	for (int i = 0;i < n;i++) wei[i] = C[i];
	for (int i = 1;i < n;i++) {
		if (type[i] == 1 || type[i] == 2){
			for (int j:adj[h[i]]) {
				adj[i].push_back(j);
				adj[j].push_back(i);
			}
		} 
		if (type[i] == 0 || type[i] == 2) {
			adj[h[i]].push_back(i);
			adj[i].push_back(h[i]);
		}
	}
	int ans = 0;
	for (int i = 0;i < (1<<n);i++) {
		vector<bool> p(n, 0);	
		int tot = 0;
		for (int j = 0;j < n;j++) {
			if ((i>>j)&1) p[j] = 1, tot += wei[j];
		}
		bool good = 1;
		for (int x = 0;x < n;x++) {
			for (int y:adj[x]) {
				if (p[x] && p[y]) {
					good = 0;
					break;
				}
			}
		}
		if (good) ans = max(ans, tot);
	}
	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...