Rt.
又是P3376,只不过换成了dicnic
本地和洛谷测了样例和测试数据 1 都没问题,但评测全 R E
代码如下:
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
struct edge
{
int next, to;
long long w;
};
int n, m, s, t, cur = 1, dis[2005], head[2005];
long long w, x, y, ans;
queue<int> q;
edge e[100005];
int add(int u, int v, long long w)
{
++cur;
e[cur] = {head[u], v, w};
head[u] = cur;
}
bool bfs()
{
while (!q.empty())
{
q.pop();
}
q.push(s);
memset(dis, 0, sizeof(dis));
dis[s] = 1;
while (!q.empty())
{
x = q.front();
q.pop();
for (register int i = head[x]; i; i = e[i].next)
{
y = e[i].to;
if (dis[y] || e[i].w == 0)
{
continue;
}
q.push(y);
dis[y] = dis[x] + 1;
if (y == t)
{
return true;
}
}
}
return false;
}
long long dicnic(int u, long long flow)
{
if (u == t)
{
return flow;
}
long long sum = 0;
for (register int i = head[u]; i; i = e[i].next)
{
x = e[i].to;
if (dis[x] != dis[u] + 1 || e[i].w == 0)
{
continue;
}
y = dicnic(x, min(flow, e[i].w));
e[i].w -= y;
e[i ^ 1].w += y;
flow -= y;
sum += y;
if (flow == 0)
{
break;
}
}
return sum;
}
int main()
{
scanf("%d%d%d%d", &n, &m, &s, &t);
while (m--)
{
scanf("%d%d%lld", &x, &y, &w);
add(x, y, w);
add(y, x, 0);
}
while (bfs())
{
ans += dicnic(s, 1e18);
}
printf("%lld", ans);
return 0;
}
若有大佬救我,我定将感激不尽!