Language: C++

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
using namespace std;

#define V 10000
#define INF 100000000

typedef pair<int,int> P;
struct edge {int to,cap,cost,rev;};

int n,m[110],g,a,b;
int x[110][30],y[110][30],c[110][30];
vector<int> time[30];

int v;
vector<edge> G[V];
int h[V];
int dist[V];
int prevv[V], preve[V];

void add_edge(int from,int to,int cap,int cost){
  G[from].push_back((edge){to,cap,cost,G[to].size()});
  G[to].push_back((edge){from,0,-cost,G[from].size() - 1});
}

int min_cost_flow(int s,int t,int f){
  int res = 0;
  fill(h,h+V,0);
  while(f>0){
    priority_queue<P ,vector<P>, greater<P> > q;
    fill(dist,dist+V,INF);
    dist[s] = 0;
    q.push(P(0,s));
    while(!q.empty()){
      P p = q.top(); q.pop();
      int v = p.second;
      if(dist[v] < p.first)continue;
      for(int i=0;i<G[v].size();i++){
	edge &e = G[v][i];
	if(e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]){
	  dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
	  prevv[e.to] = v;
	  preve[e.to] = i;
	  q.push(P(dist[e.to],e.to));
	}
      }
    }
    if(dist[t] == INF)return -1;

    for(int v=0;v<V;v++)h[v] += dist[v];

    int d = f;
    for(int v=t;v!=s;v = prevv[v]){
      d = min(d,G[prevv[v]][preve[v]].cap);
    }

    f -= d;
    res += d*h[t];
    for(int v=t;v!=s;v=prevv[v]){
      edge &e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
  return res;
}

int main(){
  while(scanf("%d",&n) != EOF, n){
    m[0] = 1; time[0].clear(); time[0].push_back(0);
    x[0][0] = 0; y[0][0] = 0; c[0][0] = 0;
    for(int i=1;i<n;i++){
      scanf("%d",&m[i]);
      for(int j=0;j<m[i];j++){
	scanf("%d %d %d",&x[i][j],&y[i][j],&c[i][j]);
	time[i].push_back(y[i][j]);
      }
      sort(time[i].begin(),time[i].end());
      time[i].erase(unique(time[i].begin(),time[i].end()),time[i].end());
    }
    m[n] = 1; time[n].clear(); time[n].push_back(1000000);
    x[n][0] = 1000000; y[n][0] = 1000000; c[n][0] = 0;
    scanf("%d",&g);

    for(int ans = g;ans>=0;ans--){
      for(int i=0;i<=V;i++)G[i].clear();
      for(int i=0;i<n;i++){
	for(int j=0;j<time[i].size();j++){
	  for(int k=0;k<m[i+1];k++){
	    if(time[i][j]<=x[i+1][k]){
	      for(int l=0;l<time[i+1].size();l++){
		if(y[i+1][k] == time[i+1][l]){
		  a = l;
		  break;
		}
	      }
	      add_edge(i*50 + j*2 + 1, (i+1)*50 + a*2, g, c[i+1][k]);
	    }
	  }
	}
	for(int j=0;j<time[i+1].size();j++)add_edge((i+1)*50 + j*2,(i+1)*50 + j*2 + 1, 1, 0);
      }
      /*
      if(ans == g){
	for(int i=0;i<V;i++){
	  for(int j=0;j<G[i].size();j++){
	    edge e = G[i][j];
	    cout << i << " " << e.to << " " << e.cap << " " << e.cost << endl;
	  }
	}
      }
      */

      int res = min_cost_flow(1,n*50,ans);
      if(0<=res){
	cout << ans << " " << res << endl;
	break;
      }
    }
  }
}

Compiler output:
a.cc:17:20: error: 'std::vector<int> time [30]' redeclared as different kind of entity
   17 | vector<int> time[30];
      |                    ^
In file included from /usr/include/pthread.h:23,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr-default.h:35,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr.h:157,
                 from /usr/include/c++/14/ext/atomicity.h:35,
                 from /usr/include/c++/14/bits/ios_base.h:39,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/time.h:76:15: note: previous declaration 'time_t time(time_t*)'
   76 | extern time_t time (time_t *__timer) __THROW;
      |               ^~~~
a.cc: In function 'void add_edge(int, int, int, int)':
a.cc:26:50: warning: narrowing conversion of 'G[to].std::vector<edge>::size()' from 'std::vector<edge>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   26 |   G[from].push_back((edge){to,cap,cost,G[to].size()});
      |                                        ~~~~~~~~~~^~
a.cc:27:54: warning: narrowing conversion of '(G[from].std::vector<edge>::size() - 1)' from 'std::vector<edge>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   27 |   G[to].push_back((edge){from,0,-cost,G[from].size() - 1});
      |                                       ~~~~~~~~~~~~~~~^~~
a.cc: In function 'int main()':
a.cc:74:21: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   74 |     m[0] = 1; time[0].clear(); time[0].push_back(0);
      |                     ^
a.cc:74:23: error: request for member 'clear' in '* time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
   74 |     m[0] = 1; time[0].clear(); time[0].push_back(0);
      |                       ^~~~~
a.cc:74:38: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   74 |     m[0] = 1; time[0].clear(); time[0].push_back(0);
      |                                      ^
a.cc:74:40: error: request for member 'push_back' in '* time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
   74 |     m[0] = 1; time[0].clear(); time[0].push_back(0);
      |                                        ^~~~~~~~~
a.cc:80:15: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   80 |         time[i].push_back(y[i][j]);
      |               ^
a.cc:80:17: error: request for member 'push_back' in '*(time + ((sizetype)i))', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
   80 |         time[i].push_back(y[i][j]);
      |                 ^~~~~~~~~
a.cc:82:18: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   82 |       sort(time[i].begin(),time[i].end());
      |                  ^
a.cc:82:20: error: request for member 'begin' in '*(time + ((sizetype)i))', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
   82 |       sort(time[i].begin(),time[i].end());
      |                    ^~~~~
a.cc:82:34: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   82 |       sort(time[i].begin(),time[i].end());
      |                                  ^
a.cc:82:36: error: request for member 'end' in '*(time + ((sizetype)i))', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
   82 |       sort(time[i].begin(),time[i].end());
      |                                    ^~~
a.cc:83:13: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   83 |       time[i].erase(unique(time[i].begin(),time[i].end()),time[i].end());
      |             ^
a.cc:83:15: error: request for member 'erase' in '*(time + ((sizetype)i))', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
   83 |       time[i].erase(unique(time[i].begin(),time[i].end()),time[i].end());
      |               ^~~~~
a.cc:83:34: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   83 |       time[i].erase(unique(time[i].begin(),time[i].end()),time[i].end());
      |                                  ^
a.cc:83:36: error: request for member 'begin' in '*(time + ((sizetype)i))', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
   83 |       time[i].erase(unique(time[i].begin(),time[i].end()),time[i].end());
      |                                    ^~~~~
a.cc:83:50: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   83 |       time[i].erase(unique(time[i].begin(),time[i].end()),time[i].end());
      |                                                  ^
a.cc:83:52: error: request for member 'end' in '*(time + ((sizetype)i))', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
   83 |       time[i].erase(unique(time[i].begin(),time[i].end()),time[i].end());
      |                                                    ^~~
a.cc:83:65: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   83 |       time[i].erase(unique(time[i].begin(),time[i].end()),time[i].end());
      |                                                                 ^
a.cc:83:67: error: request for member 'end' in '*(time + ((sizetype)i))', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
   83 |       time[i].erase(unique(time[i].begin(),time[i].end()),time[i].end());
      |                                                                   ^~~
a.cc:85:21: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   85 |     m[n] = 1; time[n].clear(); time[n].push_back(1000000);
      |                     ^
a.cc:85:23: error: request for member 'clear' in '*(time + ((sizetype)n))', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
   85 |     m[n] = 1; time[n].clear(); time[n].push_back(1000000);
      |                       ^~~~~
a.cc:85:38: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   85 |     m[n] = 1; time[n].clear(); time[n].push_back(1000000);
      |                                      ^
a.cc:85:40: error: request for member 'push_back' in '*(time + ((sizetype)n))', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
   85 |     m[n] = 1; time[n].clear(); time[n].push_back(1000000);
      |                                        ^~~~~~~~~
a.cc:92:29: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   92 |         for(int j=0;j<time[i].size();j++){
      |                             ^
a.cc:92:31: error: request for member 'size' in '*(time + ((sizetype)i))', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
   92 |         for(int j=0;j<time[i].size();j++){
      |                               ^~~~
a.cc:94:22: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   94 |             if(time[i][j]<=x[i+1][k]){
      |                      ^
a.cc:94:25: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   94 |             if(time[i][j]<=x[i+1][k]){
      |                         ^
a.cc:94:26: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   94 |             if(time[i][j]<=x[i+1][k]){
      |                ~~~~~~~~~~^~~~~~~~~~~
a.cc:95:37: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   95 |               for(int l=0;l<time[i+1].size();l++){
      |                                     ^
cc1plus: warning: pointer to a function used in arithmetic [-Wpointer-arith]
a.cc:95:39: error: request for member 'size' in '*(time + (((sizetype)i) + 1))', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
   95 |               for(int l=0;l<time[i+1].size();l++){
      |                                       ^~~~
a.cc:96:41: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   96 |                 if(y[i+1][k] == time[i+1][l]){
      |                                         ^
cc1plus: warning: pointer to a function used in arithmetic [-Wpointer-arith]
a.cc:96:44: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   96 |                 if(y[i+1][k] == time[i+1][l]){
      |                                            ^
a.cc:96:30: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   96 |                 if(y[i+1][k] == time[i+1][l]){
      |                    ~~~~~~~~~~^~~~~~~~~~~~~~~
a.cc:105:31: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  105 |         for(int j=0;j<time[i+1].size();j++)add_edge((i+1)*50 + j*2,(i+1)*50 + j*2 + 1, 1, 0);
      |                               ^
cc1plus: warning: pointer to a function used in arithmetic [-Wpointer-arith]
a.cc:105:33: error: request for member 'size' in '*(time + (((sizetype)i) + 1))', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
  105 |         for(int j=0;j<time[i+1].size();j++)add_edge((i+1)*50 + j*2,(i+1)*50 + j*2 + 1, 1, 0);
      |                                 ^~~~