Submission #986696

#TimeUsernameProblemLanguageResultExecution timeMemory
986696beabossFriend (IOI14_friend)C++14
100 / 100
22 ms4956 KiB
// Source: https://oj.uz/problem/view/IOI14_friend?locale=en
// 
#include "friend.h"

#include "bits/stdc++.h"

using namespace std;

#define s second
#define f first
#define pb push_back

typedef long long ll;

typedef pair<ll, ll> pii;
typedef vector<pii> vpii;

typedef vector<ll> vi;

#define FOR(i, a, b) for (ll i = (a); i<b; i++)

bool ckmin(ll& a, ll b){ return b < a ? a = b, true : false; }

bool ckmax(ll& a, ll b){ return b > a ? a = b, true : false; }

const ll N = 1e5 + 10;
ll c[N];

vi adj[N];


int findSample(int n, int confidence[], int host[], int protocol[]) {
// int findSample(ll n, vi confidence, vi host, vi protocol) {

	// vi bst = {0, 0};

	// bst[0] += confidence[0];
	// c[0] = 0;

	// FOR(i, 1, n) {
	// 	// cout << i << endl;
	// 	if (protocol[i] == 2) {
	// 		adj[i].pb(host[i]);
	// 		adj[host[i]].pb(i);
	// 	}
	// }

	// vector<bool> vis(n, false);
	// FOR(i, 0, n) {
	// 	// cout << i 
	// 	if (!vis[i]) {
	// 		queue<ll> q;
	// 		q.push(i);
	// 		vis[i]=true;
	// 		ll best = 0;
	// 		while (!q.empty()) {
	// 			auto cur = q.front();
	// 			q.pop();
	// 			// cout << cur << endl;
	// 			best = max(best, (ll) confidence[cur]);
	// 			for (auto val: adj[cur]) if (!vis[val]) {
	// 				vis[val]=true;
	// 				q.push(val);
	// 			}
	// 		}
	// 		// cout << i << best << endl;
	// 		confidence[i]=best;
	// 	}
	// }
	int res = 0;
	for (int i = n-1; i >= 1; i--) {
		// cout << ' ' << i << host[i] << protocol[i] << endl;
		if (protocol[i] == 1) {
			confidence[host[i]] += confidence[i];
			// c[i] = c[host[i]];
			// bst[c[i]] += confidence[i];
		} else if (protocol[i] == 2) {
			confidence[host[i]] = max(confidence[host[i]], confidence[i]);
			// c[i] = !c[host[i]];
			// bst[c[i]] += confidence[i];
		} else {
			confidence[host[i]] = max(confidence[host[i]] - confidence[i], 0);
			res += confidence[i];
		}
		// } else {
		// 	bst[c[host[i]]] -= confidence[host[i]];
		// 	bst[c[host[i]]] += max(confidence[host[i]], confidence[i]);
		// }
		// if (protocol[i] != 2) cout << i << bst[c[i]] << endl;
	}

	return res + confidence[0];
}

// int main() {
// 	ios::sync_with_stdio(false);
// 	cin.tie(nullptr);
// 	ll n;
// 	cin >> n;
// 	vi c(n);
// 	FOR(i, 0, n) cin >> c[i];
// 	vi prot(n);
// 	vi host(n);
// 	FOR(i, 1, n) cin >> host[i] >> prot[i];

// 	cout << findSample(n, c, host, prot) << endl;

// }













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