#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>>m; PrimalDual G(n); for(Int i=0;i>u>>v>>c>>d; u--;v--; G.add_edge(u,v,1,c); G.add_edge(v,u,1,c); G.add_edge(u,v,1,d); G.add_edge(v,u,1,d); } G.build(0,n-1,2); cout<