text: >(os<<'(',t); return os<<')'; } template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))> basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){ os<<'['; for(auto i=begin(c);i!=end(c);++i) os<<(i==begin(c)?"":" ")<<*i; return os<<']'; } constexpr int INF=1e9; constexpr int MOD=1e9+7; constexpr double EPS=1e-9; bool GaussJordan(const vvd& _a,const vd& b,vd& x) { int n=_a.size(); vvd a(n,vd(n+1)); rep(i,n){ copy(all(_a[i]),begin(a[i])); a[i][n]=b[i]; } rep(i,n){ int p=i; repi(j,i+1,n) if(abs(a[p][i])<abs(a[j][i])) p=j; if(abs(a[p][i])<EPS) return false; swap(a[i],a[p]); peri(j,i,n+1) a[i][j]/=a[i][i]; rep(j,n) if(j!=i) peri(k,i,n+1) a[j][k]-=a[j][i]*a[i][k]; } rep(i,n) x[i]=a[i][n]; return true; } struct Edge{ int src,dst; double cost; int cap,flow; Edge(){} Edge(int s,int d,double co,int ca=0,int f=0):src(s),dst(d),cost(co),cap(ca),flow(f){} }; bool operator<(const Edge& a,const Edge& b){return a.cost<b.cost;} bool operator>(const Edge& a,const Edge& b){return a.cost>b.cost;} struct Graph{ vector<Edge> es; vi head,next; Graph(){} Graph(int n):head(n,-1){} // コスト:-co,容量:0の逆辺も追加する void AddEdge(int u,int v,double co,int ca){ es.emplace_back(u,v,co,ca); next.push_back(head[u]); head[u]=es.size()-1; es.emplace_back(v,u,-co,0); next.push_back(head[v]); head[v]=es.size()-1; } }; double MinCostFlow(Graph& g,int tap,int sink,int flow) { int n=g.head.size(); double res=0; vd pots(n); while(flow>EPS){ vd cost(n,INF); vi prev(n,-1); priority_queue<Edge,vector<Edge>,greater<Edge>> pq; pq.emplace(-1,tap,0); while(pq.size()){ Edge cur=pq.top(); pq.pop(); if(cur.cost>cost[cur.dst]-EPS) continue; cost[cur.dst]=cur.cost; prev[cur.dst]=cur.src; for(int i=g.head[cur.dst];i!=-1;i=g.next[i]){ Edge e=g.es[i]; if(e.cap-e.flow==0) continue; pq.emplace(i,e.dst,cost[e.src]+e.cost+pots[e.src]-pots[e.dst]); } } if(cost[sink]==INF) return -1; rep(i,n) pots[i]+=cost[i]; int augment=flow; for(int v=sink;v!=tap;v=g.es[prev[v]].src){ Edge e=g.es[prev[v]]; augment=min(augment,e.