#include using namespace std; #define ALL(x) begin(x),end(x) #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b ostream &operator<<(ostream &os,const vector&v){ for(int i=0;i<(int)v.size();i++) os< istream &operator>>(istream &is,vector&v){ for(T &x:v)is>>x; return is; } // https://ei1333.github.io/library/graph/flow/primal-dual.hpp template struct PrimalDual{ struct edge{ int to; flow_t cap; cost_t cost; int rev;//この辺の逆辺がg[from]の何番目にあるか bool isrev; }; vector> graph; vector potential,min_cost; vector prevv,preve;//点,辺 const cost_t TINF; PrimalDual(int V):graph(V),TINF(numeric_limits::max()){} void add_edge(int from,int to,flow_t cap,cost_t cost){ graph[from].push_back((edge){to,cap,cost,(int)graph[to].size(),false}); graph[to].push_back((edge){from,0,-cost,(int)graph[from].size()-1,true}); } cost_t min_cost_flow(int s,int t,flow_t f,bool &ok){ int V=(int)graph.size(); cost_t ret=0; using Pi=pair; priority_queue,greater> que; potential.assign(V,0); preve.assign(V,-1); prevv.assign(V,-1); while(f>0){ min_cost.assign(V,TINF); que.emplace(0,s); min_cost[s]=0; //dijkstraパート while(!que.empty()){ Pi p=que.top();que.pop(); if(min_cost[p.second]0 and min_cost[e.to]>nextCost){ min_cost[e.to]=nextCost; prevv[e.to]=p.second,preve[e.to]=i; que.emplace(min_cost[e.to],e.to); } } } if(min_cost[t]==TINF){ ok=false; return ret; } // dijkstraの結果に応じてpotentialを調節 for(int v=0;v"<>N>>K; PrimalDual flow(N+N+40); int src=N+N,sink=N+N+1; flow.add_edge(src,0,K,0); flow.add_edge(N+N-1,sink,K,0); rep(i,N){ flow.add_edge(i,i+N,K,0); if(i+1 A(N); rep(i,N){ int t;cin>>A[i]>>t; rep(j,t){ int a;cin>>a;a--; flow.add_edge(a+N,i,1,-(A[i]-A[a])); } } flow.add_edge(src,sink,INF,0); bool ok=false; int mx=K; int res=flow.min_cost_flow(src,sink,mx,ok); cout<<-res<