Submission #129345

# Submission time Handle Problem Language Result Execution time Memory
129345 2019-07-12T04:28:29 Z antimirage Friend (IOI14_friend) C++14
Compilation error
0 ms 0 KB
#include "friend.h"
//#include "grader.cpp"
#include <bits/stdc++.h>

#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define all(s) s.begin(), s.end()

using namespace std;

const int N = 1005;

vector <int> g[N];

int a[N], dp[N][2], u[N], sum1. sum2;

void dfs (int v, int p = -1) {
	
	dp[v][1] = a[v];
	
	for (auto to : g[v]) {
		if (to == p) continue;
		dfs(to, v);
		
		dp[v][1] += dp[to][0];
		dp[v][0] += max(dp[to][0], dp[to][1]);
	}
}
void dfs2 (int v, int color) {
	u[v] = 1;
	if (color)
		sum1 += a[v];
	else
		sum2 += a[v];
	
	for (auto to : g[v]) {
		if (u[to]) continue;
		dfs2(to, color ^ 1);
	}
}
int findSample(int n, int val[], int batya[], int type[]) {
	
	int ans = 0;
	
	bool fl = 1;
	
	for (int i = 0; i < n; i++) {
		if (val[i] != 1) {
			fl = 0;
		}
	}
	if (fl) {
		a[0] = val[0];
		for (int i = 1; i < n; i++) {
			a[i] = val[i];
			if (type[i] == 0) {
				g[batya[i]].pb(i);
				g[i].pb(batya[i]);
			}
			else if (type[i] == 1) {
				for (auto it: g[batya[i]]) {
					g[i].pb(it);
					g[it].pb(i);
				}
			}
			else {
				g[batya[i]].pb(i);
				g[i].pb(batya[i]);
				for (auto it: g[batya[i]]) {
					g[i].pb(it);
					g[it].pb(i);
				}	
			}
		}
		for (int i = 0; i < n; i++) {
			if (u[i]) continue;
			sum1 = sum2 = 0;
			dfs2(i, 0);
			ans += max(sum1, sum2);
		}
	}
	else if (type[1] == 1) {
		for (int i = 0; i < n; i++) {
			ans += val[i];
		}
	}
	else if (type[1] == 2) {
		for (int i = 0; i < n; i++) {
			ans = max(ans, val[i]);
		}
	}
	else {
		a[0] = val[0];
		for (int i = 1; i < n; i++) {
			assert(batya[i] < i);
			g[batya[i]].pb(i);
			g[i].pb(batya[i]);
			a[i] = val[i];
		}
		dfs(0);
		ans = max(dp[0][0], dp[0][1]);
	}
	return ans;
}

Compilation message

friend.cpp:17:31: error: expected initializer before '.' token
 int a[N], dp[N][2], u[N], sum1. sum2;
                               ^
friend.cpp: In function 'void dfs2(int, int)':
friend.cpp:34:3: error: 'sum1' was not declared in this scope
   sum1 += a[v];
   ^~~~
friend.cpp:36:3: error: 'sum2' was not declared in this scope
   sum2 += a[v];
   ^~~~
friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:79:4: error: 'sum1' was not declared in this scope
    sum1 = sum2 = 0;
    ^~~~
friend.cpp:79:11: error: 'sum2' was not declared in this scope
    sum1 = sum2 = 0;
           ^~~~