Submission #224561

#TimeUsernameProblemLanguageResultExecution timeMemory
224561T0p_Race (IOI11_race)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
#include "race.h"
 
#define pb push_back
 
struct edge
{
	int node, weight;	
};
 
int k, ans = 1e9;
vector<edge> g[100100];
map<int, int> dp[100100];
 
void dfs(int now, int par)
{
	for(auto x : g[now])
	{
		if(x.node == now) continue ;
		dfs(x.node, now);
	}
	for(auto x : g[now])
	{
		if(x.node == now) continue ;
		for(auto it : dp[x.node])
		{
			int a = x.weight + it.first;
			int b = k - a;
			if(b <= 0) continue ;
			if(dp[now].count(b)) ans = min(ans, dp[now][b] + it.second + 1);
		}
		for(auto it : dp[x.node])
		{
			int w = it.first + x.weight;
			if(w > k) continue ;
			else if(w == k) ans = min(ans, it.second + 1);
			else if(dp[now].count(w)) dp[now][w] = min(dp[now][w], it.second + 1);
			else dp[now][w] = it.second + 1;
		}
		free(dp[x.node]);
	}
	dp[now][0] = 0;
}
 
int best_path(int N, int K, int H[][2], int L[])
{
	k = K;
	for(int i=0 ; i<N-1 ; i++)
	{
		int u = H[i][0] + 1, v = H[i][1] + 1, w = L[i];
		g[u].pb({v, w}), g[v].pb({u, w});
	}
	dfs(1, 0);
	if(ans == 1e9) ans = -1;
	return ans;
}

Compilation message (stderr)

race.cpp: In function 'void dfs(int, int)':
race.cpp:41:18: error: cannot convert 'std::map<int, int>' to 'void*' for argument '1' to 'void free(void*)'
   free(dp[x.node]);
                  ^