Submission #874112

# Submission time Handle Problem Language Result Execution time Memory
874112 2023-11-16T09:22:16 Z siewjh Friend (IOI14_friend) C++17
Compilation error
0 ms 0 KB
#include "friend.h"
const int MAXN = 100005;
vector<int> adj[MAXN];
int dp[MAXN][2], conf[MAXN];
int dfs(int x, bool take){
	if (dp[x][take] != -1) return dp[x][take];
	int ans = 0;
	if (take){
		ans = conf[x];
		for (int nxt : adj[x]) ans += dfs(nxt, 0);
	}
	else{
		for (int nxt : adj[x]) ans += max(dfs(nxt, 1), dfs(nxt, 0));
	}
	return dp[x][take] = ans;
}

// Find out best sample
int findSample(int n, int confidence[], int host[], int protocol[]){
	if (protocol[1] = 0){
		for (int i = 1; i < n; i++) adj[host[i]].push_back(i);
		for (int i = 0; i < n; i++) conf[i] = confidence[i];x
		return max(dfs(0, 0), dfs(1, 0));
	}
	else if (protocol[1] = 1){
		int ans = 0;
		for (int i = 0; i < n; i++) ans += confidence[i];
		return ans;
	}
	else{
		int ans = 0;
		for (int i = 0; i < n; i++) ans = max(ans, confidence[i]);
		return ans;
	}
}

Compilation message

friend.cpp:3:1: error: 'vector' does not name a type
    3 | vector<int> adj[MAXN];
      | ^~~~~~
friend.cpp: In function 'int dfs(int, bool)':
friend.cpp:10:18: error: 'adj' was not declared in this scope
   10 |   for (int nxt : adj[x]) ans += dfs(nxt, 0);
      |                  ^~~
friend.cpp:13:18: error: 'adj' was not declared in this scope
   13 |   for (int nxt : adj[x]) ans += max(dfs(nxt, 1), dfs(nxt, 0));
      |                  ^~~
friend.cpp:13:33: error: 'max' was not declared in this scope
   13 |   for (int nxt : adj[x]) ans += max(dfs(nxt, 1), dfs(nxt, 0));
      |                                 ^~~
friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:20:18: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   20 |  if (protocol[1] = 0){
      |      ~~~~~~~~~~~~^~~
friend.cpp:21:31: error: 'adj' was not declared in this scope
   21 |   for (int i = 1; i < n; i++) adj[host[i]].push_back(i);
      |                               ^~~
friend.cpp:22:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   22 |   for (int i = 0; i < n; i++) conf[i] = confidence[i];x
      |   ^~~
friend.cpp:22:55: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   22 |   for (int i = 0; i < n; i++) conf[i] = confidence[i];x
      |                                                       ^
friend.cpp:22:55: error: 'x' was not declared in this scope
friend.cpp:25:23: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   25 |  else if (protocol[1] = 1){
      |           ~~~~~~~~~~~~^~~
friend.cpp:32:37: error: 'max' was not declared in this scope
   32 |   for (int i = 0; i < n; i++) ans = max(ans, confidence[i]);
      |                                     ^~~
friend.cpp:35:1: warning: control reaches end of non-void function [-Wreturn-type]
   35 | }
      | ^