#include #include #include #include #include #include #include typedef long long ll; constexpr ll inf{1000000000000000000},lim{2000000000}; constexpr int N{50},M{200}; template struct flow { int n,s,t; struct edge { int v; ll w; int next; }; edge e[(M<<1)+5]; int en,last[N+5]; void initialize(const int &n,const int &s,const int &t) { this->n=n,this->s=s,this->t=t; std::fill(last+1,last+n+1,0),en=1; } inline void add_edge(const int &u,const int &v,const ll &w) { e[++en]={v,w,last[u]},last[u]=en; e[++en]={u,0,last[v]},last[v]=en; } int dis[N+5],que[N+5]; bool bfs() { std::fill(dis+1,dis+n+1,-1); int qb{1},qe{1}; dis[t]=0,que[1]=t; while(qb<=qe) { int &u{que[qb++]}; if(u==s) { return true; } for(int i=last[u];i;i=e[i].next) { int &v{e[i].v}; if(e[i^1].w!=0&&dis[v]==-1) { dis[v]=dis[u]+1,que[++qe]=v; } } } return false; } int lst[N+5]; ll dfs(const int &u,const ll &f) { if(u==t) { return f; } ll d{0}; for(int &i=lst[u];i;i=e[i].next) { int &v{e[i].v}; if(e[i].w!=0&&dis[u]==dis[v]+1) { ll s{dfs(v,std::min(e[i].w,f-d))}; e[i].w-=s,e[i^1].w+=s,d+=s; if(d==f) { return d; } } } return d; } ll dinic() { ll res{0}; while(bfs()) { std::copy(last+1,last+n+1,lst+1); res+=dfs(s,inf); } return res; } }; flow G; std::array edge[M+5]; int val[M+5]; int main() { int n,m,k; scanf("%d%d%d",&n,&m,&k); for(int i=1;i<=m;i++) { scanf("%d%d%d%d",&edge[i][0],&edge[i][1],&edge[i][2],&edge[i][3]); } std::sort(edge+1,edge+m+1,[&](const auto &x,const auto &y)->bool { return x[2](sum,edge[i][3]); ans0+=val[i],ans1+=ll(val[i])*edge[i][2]; } if(ans0