#include using namespace std; using Int = long long; const char newl = '\n'; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a void drop(const T &x){cout< vector read(size_t n){ vector ts(n); for(size_t i=0;i>ts[i]; return ts; } // O(F E \log V) template struct PrimalDual{ struct Edge{ Int dst; Flow cap; Cost cost; Int rev; Edge(Int dst,Flow cap,Cost cost,Int rev): dst(dst),cap(cap),cost(cost),rev(rev){} }; vector> G; vector h,dist; vector prevv,preve; PrimalDual(Int n):G(n),h(n),dist(n),prevv(n),preve(n){} void add_edge(Int u,Int v,Flow cap,Cost cost){ Int e=G[u].size(); Int r=(u==v?e+1:G[v].size()); G[u].emplace_back(v,cap,cost,r); G[v].emplace_back(u,0,-cost,e); } Cost residual_cost(Int src,Edge &e){ return e.cost+h[src]-h[e.dst]; } void dijkstra(Int s){ struct P{ Cost first; Int second; P(Cost first,Int second):first(first),second(second){} bool operator<(const P&a) const{return first>a.first;} }; priority_queue

pq; dist[s]=0; pq.emplace(dist[s],s); while(!pq.empty()){ P p=pq.top();pq.pop(); Int v=p.second; if(dist[v] init=[](decltype(h) &p){ fill(p.begin(),p.end(),0); }){ res=0; init(h); const Cost INF = numeric_limits::max(); while(f>0){ fill(dist.begin(),dist.end(),INF); dijkstra(s); if(dist[t]==INF) return false; for(Int v=0;v<(Int)h.size();v++) if(dist[v]>n>>k; PrimalDual G(n); auto init=[&](auto &h)->void{ fill(h.begin(),h.end(),0); auto add_edge=[&](Int u,Int v,Int f,Int c){ G.add_edge(u,v,f,c); chmin(h[v],h[u]+c); }; vector as(n); vector> H(n); for(Int i=0;i>as[i]; Int m; cin>>m; for(Int j=0;j>p; p--; H[p].emplace_back(i); } } for(Int i=0;i