Submission #582310

#TimeUsernameProblemLanguageResultExecution timeMemory
582310JosiaFriend (IOI14_friend)C++14
27 / 100
29 ms7380 KiB
#include <bits/stdc++.h>
#include "friend.h"

using namespace std;


// vector<vector<int>> friendGraph;
// vector<int> value;


// vector<int> visited;
// int dfs(int v) {
// 	if (visited[v]) return 0;
// 	visited[v] = 1;

// 	int res = value[v];

// 	for (int i: friendGraph[v]) {
// 		res = max(res, dfs(i));
// 	}

// 	return res;
// }




// Find out best sample
int findSample(int n,int confidence[],int host[],int protocol[]){
	vector<set<int>> friends(n);
	if (n<=10) {
		for (int i = 1; i<n; i++) {
			int v = host[i];
			int type = protocol[i];
			// int value = confidence[i];

			if (type == 0) {
				for (int j = 0; j<i; j++) {
					if (j == v) {
						friends[i].insert(j);
						friends[j].insert(i);
						// friendGraph[j].push_back(i);
						// friendGraph[i].push_back(j);
						continue;
					}
				}
			}
			if (type == 1) {
				for (int j = 0; j<i; j++) {
					if (friends[v].count(j)) {
						friends[i].insert(j);
						friends[j].insert(i);
						// friendGraph[j].push_back(i);
						// friendGraph[i].push_back(j);
						continue;
					}
				}
			}
			if (type == 2) {
				for (int j = 0; j<i; j++) {
					if (friends[v].count(j) || j == v) {
						friends[i].insert(j);
						friends[j].insert(i);
						// friendGraph[j].push_back(i);
						// friendGraph[i].push_back(j);					
						continue;
					}
				}
			}
		}

		int res = 0;
		for (int i = 0; i<(1<<n); i++) {
			int tmp = 0;
			vector<int> nodes;
			for (int j = 0; j<n; j++) {
				if (i & (1<<j)) nodes.push_back(j);
			}
			bool poss = 1;
			for (int i: nodes) {
				for (int j: nodes) {
					if (friends[i].count(j)) poss = 0;
				}
			}
			if (!poss) continue;

			for (int i: nodes) {
				tmp += confidence[i];
			}
			res = max(res, tmp);

		}
		return res;
	}



	// friendGraph.clear();
	// // friendGraph.clear();
	// friendGraph.resize(n);
	// // friendGraph.resize(n);

	// visited.assign(n, 0);

	// value.assign(n, 0);
	// for (int i = 0; i<n; i++) {
	// 	value[i] = confidence[i];
	// }


	// vector<set<int>> friends(n);


	// for (int i = 0; i<n; i++) {
	// 	int v = host[i];
	// 	int type = protocol[i];
	// 	// int value = confidence[i];

	// 	if (type == 0) {
	// 		for (int j = 0; j<i; j++) {
	// 			if (j == v) {
	// 				friends[i].insert(j);
	// 				friends[j].insert(i);
	// 				friendGraph[j].push_back(i);
	// 				friendGraph[i].push_back(j);
	// 				continue;
	// 			}
	// 		}
	// 	}
	// 	if (type == 1) {
	// 		for (int j = 0; j<i; j++) {
	// 			if (friends[v].count(j)) {
	// 				friends[i].insert(j);
	// 				friends[j].insert(i);
	// 				friendGraph[j].push_back(i);
	// 				friendGraph[i].push_back(j);
	// 				continue;
	// 			}
	// 		}
	// 	}
	// 	if (type == 2) {
	// 		for (int j = 0; j<i; j++) {
	// 			if (friends[v].count(j) || j == v) {
	// 				friends[i].insert(j);
	// 				friends[j].insert(i);
	// 				friendGraph[j].push_back(i);
	// 				friendGraph[i].push_back(j);					
	// 				continue;
	// 			}
	// 		}
	// 	}
	// }

	// int res = 0;
	// for (int i = 0; i<n; i++) {
	// 	res += dfs(i);
	// }


	int res = 0;
	if (protocol[1] == 1) {
		for (int i = 0; i<n; i++) {
			res += confidence[i];
		}
	}
	if (protocol[1] == 2) {
		for (int i = 0; i<n; i++) {
			res = max(res, confidence[i]);
		}
	}

	return res;

}
#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...