Submission #208292

# Submission time Handle Problem Language Result Execution time Memory
208292 2020-03-10T15:25:52 Z Sorting Friend (IOI14_friend) C++14
Compilation error
0 ms 0 KB
#include "friend.h"
#include <bits/stdc++.h>

using namespace std;

const int kN = 1007;

vector<int> adj[kN];
pair<int, bool> dp[kN][2];

void solve(int u, bool can, int parent, int confidence[]){
	if(dp[u][can].second)
		return dp[u][can].first;

	dp[u][can].second = true;
	int &ans = dp[u][can].first;
	ans = 0;

	if(can){
		curr_ans = confidence[u];
		for(int to: adj[u]){
			if(to == parent)
				continue;

			curr_ans += solve(to, false, u, confidence);
		}
		ans = max(ans, curr_ans);
	}

	curr_ans = 0;
	for(int to: adj[u]){
		if(to == par)
			continue;

		curr_ans += solve(to, true, u, confidence);
	}
	ans = max(ans, curr_ans);

	return ans;
}

int findSample(int n, int confidence[], int host[], int protocol[]){
	for(int i = 1; i < n; ++i){
		adj[host[i]].push_back(i);
		adj[i].push_back(i);
	}

	return solve(0, true, -1, confidence);
}

Compilation message

friend.cpp: In function 'void solve(int, bool, int, int*)':
friend.cpp:13:21: error: return-statement with a value, in function returning 'void' [-fpermissive]
   return dp[u][can].first;
                     ^~~~~
friend.cpp:20:3: error: 'curr_ans' was not declared in this scope
   curr_ans = confidence[u];
   ^~~~~~~~
friend.cpp:20:3: note: suggested alternative: 'wctrans'
   curr_ans = confidence[u];
   ^~~~~~~~
   wctrans
friend.cpp:30:2: error: 'curr_ans' was not declared in this scope
  curr_ans = 0;
  ^~~~~~~~
friend.cpp:30:2: note: suggested alternative: 'wctrans'
  curr_ans = 0;
  ^~~~~~~~
  wctrans
friend.cpp:32:12: error: 'par' was not declared in this scope
   if(to == par)
            ^~~
friend.cpp:39:9: error: return-statement with a value, in function returning 'void' [-fpermissive]
  return ans;
         ^~~
friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:48:38: error: void value not ignored as it ought to be
  return solve(0, true, -1, confidence);
                                      ^