Submission #598378

#TimeUsernameProblemLanguageResultExecution timeMemory
598378ono_de206Race (IOI11_race)C++14
Compilation error
0 ms0 KiB
#include "race.h"
 
 
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ff first
#define ss second
#define in insert
 
const int mxn=2e5+10,mxk=1e6+10;
vector<pair<int,int> > g[mxn];
int global_answer=-1,n,k,vis[mxn],sub[mxn],nxt,mx;
int book_keeping,minimum_path[mxk],achievable[mxk];
 
void dfs(int to,int fr)
{
	sub[to]=1;
	for(auto &x : g[to])
	{
		if(x.ff==fr || vis[x.ff]) continue;
		dfs(x.ff,to);
		sub[to]+=sub[x.ff];
	}
}
 
void get_cen(int to,int fr,int sz)
{
	int lomx=sz-sub[to];
	for(auto &x : g[to])
	{
		if(x.ff==fr || vis[x.ff]) continue;
		get_cen(x.ff,to,sz);
		lomx=max(lomx,sub[x.ff]);
	}
	if(lomx<mx)
	{
		mx=lomx;
		nxt=to;
	}
}

void dfs2(int to,int fr,int tmp,int cnt)
{
	if(tmp>k) return;
	if (!fill)
	{
    	if (achievable[K - current_cost] == book_keeping)
     	 	if (current_length + minimum_paths[K - current_cost] < global_answer || global_answer == -1)
        		global_answer = current_length + minimum_paths[K - current_cost];
 
    if (current_cost == K)
      if (current_length < global_answer || global_answer == -1)
        global_answer = current_length;
  }
  else
  {
    if (achievable[current_cost] < book_keeping)
    {
      achievable[current_cost] = book_keeping;
      minimum_paths[current_cost] = current_length;
    }
    else if (current_length < minimum_paths[current_cost])
   	{
    	  achievable[current_cost] = book_keeping;
    	  minimum_paths[current_cost] = current_length;
    	}
  	}
	for(auto &x : g[to])
	{
		if(x.ff==fr || vis[x.ff]) continue;
		dfs2(x.ff,to,tmp+x.ss,cnt+1);
	}
}
 
void solve(int id)
{
	dfs(id,-1);
	if(sub[id]<=1) return;
	mx=sub[id];
	get_cen(id,-1,sub[id]);
	id=nxt;
	book_keeping++;
	for(auto &x : g[id])
	{
		if(vis[x.ff]) continue;
		dfs2(x.ff,id,x.ss,1,0);
		dfs2(x.ff,id,x.ss,1,1);
	}
	vis[id]=1;
	memset(cn,0,sizeof(cn));
	for(auto &x : g[id])
	{
		if(vis[x.ff]) continue;
		solve(x.ff);
	}
}
 
int best_path(int N, int K, int h[][2], int l[])
{
	n=N;
	k=K;
	memset(vis,0,sizeof(vis));
	for(int i=0; i<N-1; i++)
	{
		g[h[i][0]].pb({h[i][1],l[i]});
		g[h[i][1]].pb({h[i][0],l[i]});
	}
	solve(0);
	return global_answer;
}

Compilation message (stderr)

race.cpp: In function 'void dfs2(int, int, int, int)':
race.cpp:47:7: error: cannot resolve overloaded function 'fill' based on conversion to type 'bool'
   47 |  if (!fill)
      |       ^~~~
race.cpp:47:7: error: in argument to unary !
race.cpp:49:21: error: 'K' was not declared in this scope
   49 |      if (achievable[K - current_cost] == book_keeping)
      |                     ^
race.cpp:49:25: error: 'current_cost' was not declared in this scope
   49 |      if (achievable[K - current_cost] == book_keeping)
      |                         ^~~~~~~~~~~~
race.cpp:50:13: error: 'current_length' was not declared in this scope
   50 |         if (current_length + minimum_paths[K - current_cost] < global_answer || global_answer == -1)
      |             ^~~~~~~~~~~~~~
race.cpp:50:30: error: 'minimum_paths' was not declared in this scope; did you mean 'minimum_path'?
   50 |         if (current_length + minimum_paths[K - current_cost] < global_answer || global_answer == -1)
      |                              ^~~~~~~~~~~~~
      |                              minimum_path
race.cpp:53:9: error: 'current_cost' was not declared in this scope
   53 |     if (current_cost == K)
      |         ^~~~~~~~~~~~
race.cpp:53:25: error: 'K' was not declared in this scope
   53 |     if (current_cost == K)
      |                         ^
race.cpp:54:11: error: 'current_length' was not declared in this scope
   54 |       if (current_length < global_answer || global_answer == -1)
      |           ^~~~~~~~~~~~~~
race.cpp:59:20: error: 'current_cost' was not declared in this scope
   59 |     if (achievable[current_cost] < book_keeping)
      |                    ^~~~~~~~~~~~
race.cpp:62:7: error: 'minimum_paths' was not declared in this scope; did you mean 'minimum_path'?
   62 |       minimum_paths[current_cost] = current_length;
      |       ^~~~~~~~~~~~~
      |       minimum_path
race.cpp:62:37: error: 'current_length' was not declared in this scope
   62 |       minimum_paths[current_cost] = current_length;
      |                                     ^~~~~~~~~~~~~~
race.cpp:64:14: error: 'current_length' was not declared in this scope
   64 |     else if (current_length < minimum_paths[current_cost])
      |              ^~~~~~~~~~~~~~
race.cpp:64:31: error: 'minimum_paths' was not declared in this scope; did you mean 'minimum_path'?
   64 |     else if (current_length < minimum_paths[current_cost])
      |                               ^~~~~~~~~~~~~
      |                               minimum_path
race.cpp: In function 'void solve(int)':
race.cpp:88:24: error: too many arguments to function 'void dfs2(int, int, int, int)'
   88 |   dfs2(x.ff,id,x.ss,1,0);
      |                        ^
race.cpp:44:6: note: declared here
   44 | void dfs2(int to,int fr,int tmp,int cnt)
      |      ^~~~
race.cpp:89:24: error: too many arguments to function 'void dfs2(int, int, int, int)'
   89 |   dfs2(x.ff,id,x.ss,1,1);
      |                        ^
race.cpp:44:6: note: declared here
   44 | void dfs2(int to,int fr,int tmp,int cnt)
      |      ^~~~
race.cpp:92:9: error: 'cn' was not declared in this scope; did you mean 'n'?
   92 |  memset(cn,0,sizeof(cn));
      |         ^~
      |         n