Submission #586427

#TimeUsernameProblemLanguageResultExecution timeMemory
586427LastRoninFriend (IOI14_friend)C++14
0 / 100
1 ms596 KiB
#include "friend.h"
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const ll N = 2e3 + 10;

vector<ll> g[N];
bool was[N]; 
ll we[N];


ll col[N];
ll cnt[3] = {0};

void dfs2(ll v, ll a) {
	assert(a == 1 || a == 2);
	cnt[a] += we[v];
	assert(col[v] == 0);
	assert(was[v] == 0);
	col[v] = a;
	was[v] = 1;
	assert(col[v] == 1 || col[v] == 2);
	assert(col[v] == a);
	assert(was[v] == 1);			
	for(auto u : g[v]) {
		if(!was[u]) {
			dfs2(u, col[v]^3);
		}
		assert(col[v] == 1 || col[v] == 2);
		assert(col[u] == 1 || col[u] == 2);
		assert(col[v] != col[u]);
	}
}


int findSample(int n,int confidence[],int host[],int protocol[]){
	assert(n <= 1000);
    for(int j = 0; j < n; j++)
		we[j] = confidence[j], assert(we[j] == 1);
	for(int j = 1; j < n; j++) {
		assert(host[j] != j);
		if(protocol[j] == 0) {
			g[j].pb(host[j]);
			g[host[j]].pb(j);
		} else if(protocol[j] == 1) {
			for(auto u : g[host[j]]) {
				g[j].pb(u);
				g[u].pb(j);
			}
		} else assert(0);    
	}
	ll answ = 0;
	for(int i = 0; i < n; i++)
		col[i] = 0, was[i] = 0;
	for(int i = 0; i < n; i++) {
		if(!was[i]) {
		    cnt[1] = cnt[2] = 0;
			dfs2(i, 2);
			answ += max(cnt[1], cnt[2]);
		}
	}
	return answ;
}
/*
6
13 3 6 20 10 15
0 0 0 1 1 2 2 1 0 0
6
13 3 6 20 10 15
0 0 0 1 1 2 2 1 0 0

*/
/*
#define __MAXSIZE__ 100002
#include "friend.h"
using namespace std;

// Confidence
int confidence[__MAXSIZE__];

// Host
int host[__MAXSIZE__];

// Protocol
int protocol[__MAXSIZE__];

// Main
int main(void)
{
	int n,i;

	// Number of people
	assert(scanf("%d",&n)==1);
	
	// Confidence
	for(i=0;i<n;i++)
		assert(scanf("%d",&confidence[i])==1);
	
	// Host and Protocol
	for(i=1;i<n;i++)
		assert(scanf("%d %d",&host[i],&protocol[i])==2);
	
	// Answer
	printf("%d\n",findSample(n,confidence,host,protocol));
	return 0;
}
/**/

Compilation message (stderr)

friend.cpp:109:1: warning: "/*" within comment [-Wcomment]
  109 | /**/
      |
#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...