#include using namespace std; template struct MaxFlowGraph{ struct edge{ int to, rev; Cap cap; }; MaxFlowGraph(int n): G(n), _n(n), cap_max(0){} void add_edge(int a, int b, Cap c){ assert(0<=a && a<_n); assert(0<=b && b<_n); assert(0<=c); G[a].push_back({b, G[b].size(), c}); G[b].push_back({a, G[a].size()-1, 0}); if(cap_max < c) cap_max = c; } Cap flow(int s, int t){ Cap res = 0; while(true){ used.assign(_n, false); Cap fw = dfs(s, t, cap_max); if(fw==0)break; res += fw; } return res; } private: int _n; Cap cap_max; std::vector> G; std::vector used; Cap dfs(int v, int t, Cap f){ if(v==t) return f; used[v] = true; for(edge &e:G[v]){ if(used[e.to] || e.cap==0) continue; Cap fw = dfs(e.to, t, min(f, e.cap)); if(fw==0) continue; e.cap -= fw; G[e.to][e.rev].cap += fw; return fw; } return 0; } }; int main(){ int N,M,d; cin>>N>>M>>d; int s=2*M,t=s+1; MaxFlowGraph G(2*M+2); vector U(M),V(M),P(M),Q(M),W(M); vector>> A(N); for(int i=0;i>U[i]>>V[i]>>P[i]>>Q[i]>>W[i]; --U[i]; --V[i]; G.add_edge(2*i,2*i+1,W[i]); if(U[i]==0)G.add_edge(s,2*i,W[i]); if(V[i]==N-1)G.add_edge(2*i+1,t,W[i]); A[U[i]].push_back({P[i],i}); } for(int i=0;i