Submission #470461

#TimeUsernameProblemLanguageResultExecution timeMemory
470461NamnamseoFriend (IOI14_friend)C++17
27 / 100
3 ms2764 KiB
#include "friend.h"
#include <cstdio>
#include <vector>
using namespace std;

const int maxn = int(1e5) + 10;

vector<int> e[maxn];
int msk[maxn];
int *a;

int dfs(int x, bool pp) {
	static int dp[maxn][2]; int &ret = dp[x][pp];
	static bool vis[maxn][2];
	if (vis[x][pp]) return ret; vis[x][pp] = true;

for (int use=0; use<2; ++use) {
	if (use && pp) continue;
	int tmp = (use ? a[x] : 0);
	for (int y:e[x]) {
		tmp += dfs(y, msk[y]&(2*pp+use));
	}
	if (ret < tmp) ret = tmp;
}

	return ret;
}

int findSample(int n,int confidence[],int host[],int protocol[]){
	a = confidence;

	for (int i=1; i<n; ++i) e[host[i]].push_back(i);
	for (int i=1; i<n; ++i) msk[i] = protocol[i]+1;

	return dfs(0, 0);
}

Compilation message (stderr)

friend.cpp: In function 'int dfs(int, bool)':
friend.cpp:15:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   15 |  if (vis[x][pp]) return ret; vis[x][pp] = true;
      |  ^~
friend.cpp:15:30: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   15 |  if (vis[x][pp]) return ret; vis[x][pp] = true;
      |                              ^~~
#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...