Submission #210648

#TimeUsernameProblemLanguageResultExecution timeMemory
210648robinrstRace (IOI11_race)C++14
Compilation error
0 ms0 KiB
#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;


#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          N (int)2e5+5
#define          pb push_back
#define          mod 1000000007
#define          ld long double
#define          vi vector<int>
#define          eb emplace_back
#define          vpii vector<pii>
#define          mii map<ll,ll>
#define          ll long long 
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) rbegin(x),rend(x)
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          PI acos(-1.0)
#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > 
OS ;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

inline void INP()
{
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);   
	    freopen("output.txt","w",stdout);
	#endif 
}

const ll inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;

llll n,m,k,q,ans;
string s;
vpii adj[N];
llll in[N],out[N],sz[N],Dep[N],sumNow[N],id[N];
bool big[N];
mii path;

void dfsSize(int  i = 0, int p = -1)
{
	static int clk = 0;
	sz[i] = 1;
	in[i] = ++clk;
	id[clk] = i;

	for( auto j : adj[i] )
	{
		if( j.f != p )
		{
			sumNow[j.f] = sumNow[i] + j.sc;
			Dep[j.f] = Dep[i] + 1;
			dfsSize(j.f , i);
			sz[i] += sz[j.f];
		}
	}
	out[i] = clk;
}

#define z id[k]

void add(int i, int x)
{
	ll sum = sumNow[i];
	if( x == -1 ) path[sum] = 0;
	else
	{
		ll xx = path[sum];
		if( xx == 0 ) xx = INF;
		path[sum] = min( Dep[i] , xx );
	}
}

void dfs(int i = 0 , int p = -1, bool keep = 0)
{
	int mx = -1, bigChild = -1;

	for( auto j : adj[i] )
	{
		if( j.f != p and mx < sz[j.f] ) mx = sz[j.f] , bigChild = j.f;
	}

	for( auto j : adj[i] ) 
	{
		if( j.f != p and j.f != bigChild ) dfs(j.f , i , 0);
	}

	if( ~bigChild ) dfs(bigChild , i , 1) , big[bigChild] = 1;

	for( auto j : adj[i] )
	{
		if( j.f != p and !big[j.f] )
		{
			fo(k,in[j.f],out[j.f]+1)
			{
				ll now =  abs( sumNow[z] - sumNow[i] - m );
				if( path[now] )
				{
					ans = min( ans , path[now] + (Dep[z] - Dep[i]) - Dep[i] );
					// Minus Dep[i] in the end is because we have that added in path[now - k]
				}
			}
			fo(k,in[j.f],out[j.f]+1) add( z , 1);
		}
	}

	add(i ,1);

	// for( auto j : path ) cout << j.f << '-' << j.sc << endl;
	// cout << endl;

	if( path[ sumNow[i] + m ] ) ans = min( ans , path[ sumNow[i] + m ] - Dep[i] ); // Minus Dep[i] beacuse that is already added in path[ sumNow[i] + k]

	if( !keep )
	{
		fo(k,in[i],out[i]+1) add(z , -1);
	}
}

void go()
{
	cin >> n >> m;
	ans = INF;
	fo(i,0,n-1)
	{
		int u , v , w;
		cin >> u >> v >> w;
		adj[u].pb({ v, w} );
		adj[v].pb({ u , w} );
	}
	dfsSize();
	dfs();

	if( ans == INF ) ans = -1;
	bug(ans);
	// return ans;

}

int best_path (int N, int K, int H[][2], int L[])
{
    n = N, m = K;
    fo(i,0,n-1)
    {
        adj[H[i][0]].pb(mp(H[i][1], L[i]));
        adj[H[i][1]].pb(mp(H[i][0], L[i]));
    }
    return go();
}

// int32_t main()
// {
// 	INP(); 
// 	FAST;     
// 	int t=1; 
// 	// cin>>t;
// 	test(t) go();
// }

 

Compilation message (stderr)

race.cpp:73:1: error: 'llll' does not name a type; did you mean 'logl'?
 llll n,m,k,q,ans;
 ^~~~
 logl
race.cpp:76:1: error: 'llll' does not name a type; did you mean 'logl'?
 llll in[N],out[N],sz[N],Dep[N],sumNow[N],id[N];
 ^~~~
 logl
race.cpp: In function 'void dfsSize(int, int)':
race.cpp:83:2: error: 'sz' was not declared in this scope
  sz[i] = 1;
  ^~
race.cpp:83:2: note: suggested alternative: 's'
  sz[i] = 1;
  ^~
  s
race.cpp:84:2: error: 'in' was not declared in this scope
  in[i] = ++clk;
  ^~
race.cpp:84:2: note: suggested alternative: 'i'
  in[i] = ++clk;
  ^~
  i
race.cpp:85:2: error: 'id' was not declared in this scope
  id[clk] = i;
  ^~
race.cpp:85:2: note: suggested alternative: 'i'
  id[clk] = i;
  ^~
  i
race.cpp:91:4: error: 'sumNow' was not declared in this scope
    sumNow[j.f] = sumNow[i] + j.sc;
    ^~~~~~
race.cpp:92:4: error: 'Dep' was not declared in this scope
    Dep[j.f] = Dep[i] + 1;
    ^~~
race.cpp:97:2: error: 'out' was not declared in this scope
  out[i] = clk;
  ^~~
race.cpp:97:2: note: suggested alternative: 'putw'
  out[i] = clk;
  ^~~
  putw
race.cpp: In function 'void add(int, int)':
race.cpp:104:11: error: 'sumNow' was not declared in this scope
  ll sum = sumNow[i];
           ^~~~~~
race.cpp:104:11: note: suggested alternative: 'sum'
  ll sum = sumNow[i];
           ^~~~~~
           sum
race.cpp:110:20: error: 'Dep' was not declared in this scope
   path[sum] = min( Dep[i] , xx );
                    ^~~
race.cpp: In function 'void dfs(int, int, bool)':
race.cpp:120:25: error: 'sz' was not declared in this scope
   if( j.f != p and mx < sz[j.f] ) mx = sz[j.f] , bigChild = j.f;
                         ^~
race.cpp:120:25: note: suggested alternative: 's'
   if( j.f != p and mx < sz[j.f] ) mx = sz[j.f] , bigChild = j.f;
                         ^~
                         s
race.cpp:134:9: error: 'in' was not declared in this scope
    fo(k,in[j.f],out[j.f]+1)
         ^
race.cpp:43:38: note: in definition of macro 'fo'
 #define          fo(i,a,n) for(int i=a;i<n;i++)
                                      ^
race.cpp:134:9: note: suggested alternative: 'i'
    fo(k,in[j.f],out[j.f]+1)
         ^
race.cpp:43:38: note: in definition of macro 'fo'
 #define          fo(i,a,n) for(int i=a;i<n;i++)
                                      ^
race.cpp:134:17: error: 'out' was not declared in this scope
    fo(k,in[j.f],out[j.f]+1)
                 ^
race.cpp:43:42: note: in definition of macro 'fo'
 #define          fo(i,a,n) for(int i=a;i<n;i++)
                                          ^
race.cpp:134:17: note: suggested alternative: 'putw'
    fo(k,in[j.f],out[j.f]+1)
                 ^
race.cpp:43:42: note: in definition of macro 'fo'
 #define          fo(i,a,n) for(int i=a;i<n;i++)
                                          ^
race.cpp:136:20: error: 'sumNow' was not declared in this scope
     ll now =  abs( sumNow[z] - sumNow[i] - m );
                    ^~~~~~
race.cpp:100:11: error: 'id' was not declared in this scope
 #define z id[k]
           ^
race.cpp:136:27: note: in expansion of macro 'z'
     ll now =  abs( sumNow[z] - sumNow[i] - m );
                           ^
race.cpp:100:11: note: suggested alternative: 'i'
 #define z id[k]
           ^
race.cpp:136:27: note: in expansion of macro 'z'
     ll now =  abs( sumNow[z] - sumNow[i] - m );
                           ^
race.cpp:136:44: error: 'm' was not declared in this scope
     ll now =  abs( sumNow[z] - sumNow[i] - m );
                                            ^
race.cpp:139:6: error: 'ans' was not declared in this scope
      ans = min( ans , path[now] + (Dep[z] - Dep[i]) - Dep[i] );
      ^~~
race.cpp:139:6: note: suggested alternative: 'abs'
      ans = min( ans , path[now] + (Dep[z] - Dep[i]) - Dep[i] );
      ^~~
      abs
race.cpp:139:36: error: 'Dep' was not declared in this scope
      ans = min( ans , path[now] + (Dep[z] - Dep[i]) - Dep[i] );
                                    ^~~
race.cpp:139:36: note: suggested alternative: 'keep'
      ans = min( ans , path[now] + (Dep[z] - Dep[i]) - Dep[i] );
                                    ^~~
                                    keep
race.cpp:143:9: error: 'in' was not declared in this scope
    fo(k,in[j.f],out[j.f]+1) add( z , 1);
         ^
race.cpp:43:38: note: in definition of macro 'fo'
 #define          fo(i,a,n) for(int i=a;i<n;i++)
                                      ^
race.cpp:143:9: note: suggested alternative: 'i'
    fo(k,in[j.f],out[j.f]+1) add( z , 1);
         ^
race.cpp:43:38: note: in definition of macro 'fo'
 #define          fo(i,a,n) for(int i=a;i<n;i++)
                                      ^
race.cpp:143:17: error: 'out' was not declared in this scope
    fo(k,in[j.f],out[j.f]+1) add( z , 1);
                 ^
race.cpp:43:42: note: in definition of macro 'fo'
 #define          fo(i,a,n) for(int i=a;i<n;i++)
                                          ^
race.cpp:143:17: note: suggested alternative: 'putw'
    fo(k,in[j.f],out[j.f]+1) add( z , 1);
                 ^
race.cpp:43:42: note: in definition of macro 'fo'
 #define          fo(i,a,n) for(int i=a;i<n;i++)
                                          ^
race.cpp:100:11: error: 'id' was not declared in this scope
 #define z id[k]
           ^
race.cpp:143:34: note: in expansion of macro 'z'
    fo(k,in[j.f],out[j.f]+1) add( z , 1);
                                  ^
race.cpp:100:11: note: suggested alternative: 'i'
 #define z id[k]
           ^
race.cpp:143:34: note: in expansion of macro 'z'
    fo(k,in[j.f],out[j.f]+1) add( z , 1);
                                  ^
race.cpp:152:12: error: 'sumNow' was not declared in this scope
  if( path[ sumNow[i] + m ] ) ans = min( ans , path[ sumNow[i] + m ] - Dep[i] ); // Minus Dep[i] beacuse that is already added in path[ sumNow[i] + k]
            ^~~~~~
race.cpp:152:24: error: 'm' was not declared in this scope
  if( path[ sumNow[i] + m ] ) ans = min( ans , path[ sumNow[i] + m ] - Dep[i] ); // Minus Dep[i] beacuse that is already added in path[ sumNow[i] + k]
                        ^
race.cpp:152:24: note: suggested alternative: 'mx'
  if( path[ sumNow[i] + m ] ) ans = min( ans , path[ sumNow[i] + m ] - Dep[i] ); // Minus Dep[i] beacuse that is already added in path[ sumNow[i] + k]
                        ^
                        mx
race.cpp:152:30: error: 'ans' was not declared in this scope
  if( path[ sumNow[i] + m ] ) ans = min( ans , path[ sumNow[i] + m ] - Dep[i] ); // Minus Dep[i] beacuse that is already added in path[ sumNow[i] + k]
                              ^~~
race.cpp:152:30: note: suggested alternative: 'abs'
  if( path[ sumNow[i] + m ] ) ans = min( ans , path[ sumNow[i] + m ] - Dep[i] ); // Minus Dep[i] beacuse that is already added in path[ sumNow[i] + k]
                              ^~~
                              abs
race.cpp:152:71: error: 'Dep' was not declared in this scope
  if( path[ sumNow[i] + m ] ) ans = min( ans , path[ sumNow[i] + m ] - Dep[i] ); // Minus Dep[i] beacuse that is already added in path[ sumNow[i] + k]
                                                                       ^~~
race.cpp:152:71: note: suggested alternative: 'keep'
  if( path[ sumNow[i] + m ] ) ans = min( ans , path[ sumNow[i] + m ] - Dep[i] ); // Minus Dep[i] beacuse that is already added in path[ sumNow[i] + k]
                                                                       ^~~
                                                                       keep
race.cpp:156:8: error: 'in' was not declared in this scope
   fo(k,in[i],out[i]+1) add(z , -1);
        ^
race.cpp:43:38: note: in definition of macro 'fo'
 #define          fo(i,a,n) for(int i=a;i<n;i++)
                                      ^
race.cpp:156:8: note: suggested alternative: 'i'
   fo(k,in[i],out[i]+1) add(z , -1);
        ^
race.cpp:43:38: note: in definition of macro 'fo'
 #define          fo(i,a,n) for(int i=a;i<n;i++)
                                      ^
race.cpp:156:14: error: 'out' was not declared in this scope
   fo(k,in[i],out[i]+1) add(z , -1);
              ^
race.cpp:43:42: note: in definition of macro 'fo'
 #define          fo(i,a,n) for(int i=a;i<n;i++)
                                          ^
race.cpp:156:14: note: suggested alternative: 'putw'
   fo(k,in[i],out[i]+1) add(z , -1);
              ^
race.cpp:43:42: note: in definition of macro 'fo'
 #define          fo(i,a,n) for(int i=a;i<n;i++)
                                          ^
race.cpp:100:11: error: 'id' was not declared in this scope
 #define z id[k]
           ^
race.cpp:156:28: note: in expansion of macro 'z'
   fo(k,in[i],out[i]+1) add(z , -1);
                            ^
race.cpp:100:11: note: suggested alternative: 'i'
 #define z id[k]
           ^
race.cpp:156:28: note: in expansion of macro 'z'
   fo(k,in[i],out[i]+1) add(z , -1);
                            ^
race.cpp: In function 'void go()':
race.cpp:162:9: error: 'n' was not declared in this scope
  cin >> n >> m;
         ^
race.cpp:162:14: error: 'm' was not declared in this scope
  cin >> n >> m;
              ^
race.cpp:163:2: error: 'ans' was not declared in this scope
  ans = INF;
  ^~~
race.cpp:163:2: note: suggested alternative: 'abs'
  ans = INF;
  ^~~
  abs
race.cpp: At global scope:
race.cpp:180:16: error: expected primary-expression before 'int'
 int best_path (int N, int K, int H[][2], int L[])
                ^~~
race.cpp:180:23: error: expected primary-expression before 'int'
 int best_path (int N, int K, int H[][2], int L[])
                       ^~~
race.cpp:180:30: error: expected primary-expression before 'int'
 int best_path (int N, int K, int H[][2], int L[])
                              ^~~
race.cpp:180:42: error: expected primary-expression before 'int'
 int best_path (int N, int K, int H[][2], int L[])
                                          ^~~
race.cpp:180:49: error: expression list treated as compound expression in initializer [-fpermissive]
 int best_path (int N, int K, int H[][2], int L[])
                                                 ^