#include using namespace std; using ll =long long; #define all(v) v.begin(),v.end() #define rep(i,a,b) for(int i=a;i=b;i--) ll INF=2e18; struct edge {ll to,cap,rev;}; ll V; vector> G; vector level; vector iter; void add_edge( ll from,ll to,ll cap){ G[from].push_back({to,cap,G[to].size()}); G[to].push_back({from,0,G[from].size()-1}); } void bfs(ll s) { level=vector (V,-1); queue que; level[s]=0; que.push(s); while(!que.empty()) { ll v=que.front(); que.pop(); for(ll i=0;i0&&level[e.to]<0) { level[e.to]=level[v]+1; que.push(e.to); } } } } ll dfs(ll v,ll t,ll f) { if(v==t) return f; for(ll &i=iter[v];i0&&level[v]0) { e.cap-=d; G[e.to][e.rev].cap+=d; return d; } } } return 0; } ll max_flow(ll s,ll t) { ll flow=0; for(;;) { bfs(s); if(level[t]<0) return flow; iter=vector (V,0); ll f; while((f=dfs(s,t,INF))>0) { flow+=f; } } } int main() { ll N,M,d;cin>>N>>M>>d; vector> t(N,vector (0)); vector u(M); vector v(M); vector p(M); vector q(M); vector w(M); for(ll i=0;i>u[i]>>v[i]>>p[i]>>q[i]>>w[i]; u[i]--;v[i]--; t[u[i]].push_back(p[i]); t[v[i]].push_back(q[i]+d); } for(ll i=0;i>> note(N,vector> (0)); ll count=0; for(ll i=0;i num(0); ll now=-1; for(auto x:t[i]) { if(now!=x) { now=x; num.push_back(now); } } for(auto x:num) { note[i].push_back({x,count}); count++; } } V=count; G=vector> (V,vector (0)); for(ll i=0;i