Submission #1232934

#TimeUsernameProblemLanguageResultExecution timeMemory
1232934kl0989eFriend (IOI14_friend)C++20
0 / 100
1 ms328 KiB
#include "friend.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pi pair<int, int>
#define pl pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()

/*const int maxn=10;

vector<vi> graph(maxn,vi(maxn,0));

int findSample(int n, int val[], int host[], int prot[]) {// sub1
	for (int i=1; i<n; i++) {
		if (prot[i]==0 || prot[i]==2) {
			graph[i][host[i]]=1;
			graph[host[i]][i]=1;
		}
		if (prot[i]) {
			for (int j=0; j<n; j++) {
				graph[i][j]|=graph[host[i]][j];
				graph[j][i]|=graph[host[i]][j];
			}
		}
	}
	int mx=0;
	for (int i=0; i<(1<<n); i++) {
		bool ok=1;
		for (int j=0; j<n && ok; j++) {
			for (int k=j+1; k<n && ok; k++) {
				if ((i&(1<<j)) && (i&(1<<k)) && graph[j][k]) {
					ok=0;
				}
			}
		}
		if (ok) {
			int cur=0;
			for (int j=0; j<n; j++) {
				if (i&(1<<j)) {
					cur+=val[j];
				}
			}
			mx=max(mx,cur);
		}
	}
	return mx;
}*/

/*int findSample(int n, int val[], int host[], int prot[]) {// sub2
	return accumulate(val,val+n,0);
}*/

/*int findSample(int n, int val[], int host[], int prot[]) {// sub3
	return *max_element(val,val+n);
}*/

/*const int maxn=1010;

vector<vi> graph(maxn);
vector<pi> dp(maxn,pi({0,0}));

void dfs(int cur, int prev=-1) {
	for (auto to:graph[cur]) {
		if (to==prev) {
			continue;
		}
		dfs(to,cur);
		dp[cur].fi+=dp[to].se;
		dp[cur].se+=max(dp[to].fi,dp[to].se);
	}
}

int findSample(int n, int val[], int host[], int prot[]) {// sub4
	for (int i=0; i<n; i++) {
		dp[i].fi=val[i];
	}
	for (int i=1; i<n; i++) {
		graph[i].pb(host[i]);
		graph[host[i]].pb(i);
	}
	dfs(0);
	return max(dp[0].fi,dp[0].se);
}*/

const int maxn=1010;

vector<vi> graph(maxn);
vi seen(maxn);
int t=0;
int cnt=0;

void dfs(int cur, int mul=1) {
	seen[cur]=1;
	t+=mul;
	cnt++;
	for (auto to:graph[cur]) {
		if (seen[to]) {
			continue;
		}
		dfs(to,mul^1);
	}
}

int findSample(int n, int val[], int host[], int prot[]) {// sub5
	for (int i=1; i<n; i++) {
		graph[i].pb(host[i]);
		graph[host[i]].pb(i);
	}
	int ans=0;
	for (int i=0; i<n; i++) {
		if (!seen[i]) {
			t=0;
			cnt=0;
			dfs(i);
			ans+=max(cnt-t,t);
		}
	}
	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...