UPD: 为啥网上题解和我都不一样？？我的做法是错的吗？？求教

代码

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

const int N = 1002;
const int M = 8000;
const int INF = 1e7;

namespace MaxFlow
{
struct Edge
{
int v,w,nxt,rev;
} e[(M<<1)+3];
int n,en,s,t;
int dep[N+3];
int que[N+3];
int fe[N+3];
int te[N+3];
void clear()
{
for(int i=1; i<=n; i++) fe[i] = te[i] = 0;
for(int i=1; i<=en; i++) e[i].v = e[i].w = e[i].nxt = e[i].rev = 0;
n = en = s = t = 0;
}
{
en++; e[en].v = v; e[en].w = w;
e[en].nxt = fe[u]; fe[u] = en; e[en].rev = en+1;
en++; e[en].v = u; e[en].w = 0;
e[en].nxt = fe[v]; fe[v] = en; e[en].rev = en-1;
}
bool bfs()
{
for(int i=1; i<=n; i++) dep[i] = 0;
int head = 1,tail = 1; que[tail] = s; dep[s] = 1;
{
for(int i=fe[u]; i; i=e[i].nxt)
{
if(dep[e[i].v]==0 && e[i].w>0)
{
dep[e[i].v] = dep[u]+1;
tail++; que[tail] = e[i].v;
}
}
}
return dep[t]!=0;
}
int dfs(int u,int cur)
{
if(u==t) {return cur;}
int rst = cur;
for(int i=te[u]; i; i=e[i].nxt)
{
if(dep[e[i].v]==dep[u]+1 && e[i].w>0 && rst>0)
{
int flow = dfs(e[i].v,min(rst,e[i].w));
if(flow>0)
{
rst -= flow; e[i].w -= flow; e[e[i].rev].w += flow;
if(e[i].w>0) te[u] = i;
if(rst==0) {return cur;}
}
}
}
return cur-rst;
}
int dinic(int _n,int _s,int _t)
{
n = _n,s = _s,t = _t;
int ret = 0;
while(bfs())
{
for(int i=1; i<=n; i++) te[i] = fe[i];
ret += dfs(s,INF);
}
return ret;
}
}
using MaxFlow::dinic;

struct AEdge
{
int u,v,w1,w2;
} ae[M+3];
int dui[N+3],duo[N+3],du[N+3];
int n,m;

void clear()
{
for(int i=1; i<=n; i++) dui[i] = duo[i] = 0;
MaxFlow::clear();
}

int main()
{
scanf("%d%d",&n,&m); int left = 0,right = 0;
for(int i=1; i<=m; i++)
{
scanf("%d%d%d%d",&ae[i].u,&ae[i].v,&ae[i].w1,&ae[i].w2);
left = max(left,min(ae[i].w1,ae[i].w2));
right = max(right,max(ae[i].w1,ae[i].w2));
du[ae[i].u]++; du[ae[i].v]++;
}
for(int i=1; i<=n; i++)
{
if(du[i]&1) {printf("NIE"); return 0;}
}
while(left<right)
{
int mid = left+((right-left)>>1);
int std = 0;
for(int i=1; i<=m; i++)
{
if(ae[i].w1<=mid && ae[i].w2<=mid)
{
}
else if(ae[i].w1<=mid)
{
duo[ae[i].u]++; dui[ae[i].v]++;
}
else if(ae[i].w2<=mid)
{
duo[ae[i].v]++; dui[ae[i].u]++;
}
}
for(int i=1; i<=n; i++)
{
if(dui[i]>duo[i])
{
std += dui[i]-duo[i];
}
else if(duo[i]>dui[i])
{