# include
# include
# define inf 0x3f3f3f3f
# define maxn 1000 +10
# define maxe 400000 +10
using namespace std;
typedef struct Edge {
int from, to, c, w, next;
} Edge;
Edge edge [maxe];
int head [maxn];
int s, t, n, m, k, p, cnt;
int dist [maxn], pre [maxn];
bool in [maxn];
int min (int a, int b)
{
return a
}
void add (int u, int v, int c, int w)
{
edge [cnt]. from = u; edge [cnt]. to = v; edge [cnt]. c = c; edge [cnt]. w = w;
edge [cnt]. next = head [u]; head [u] = cnt + +;
edge [cnt]. from = v; edge [cnt]. to = u; edge [cnt]. c = 0; edge [cnt]. w =-w;
edge [cnt]. next = head [v]; head [v] = cnt + +;
return;
}
int spfa ()
{
int i;
queue
memset (in, 0, sizeof (in));
memset (pre, -1, sizeof (pre));
for (i = 0; i <= t; i + +) dist [i] = inf;
in [s] = 1;
dist [s] = 0;
q.push (s);
while (! q.empty ())
{
int u = q.front (); q.pop ();
in [u] = 0;
for (i = head [u]; i! = -1; i = edge [i]. next)
{
int v = edge [i]. to, c = edge [i]. c, w = edge [i]. w;
if (c && dist [u] + w
dist [v] = dist [u] + w; pre [ v] = i;
if (! in [v])
{
in [v] = 1 ;
q.push (v) ;
}
}
}
}
if (dist [t] == ??inf) return 0;
int p, delta = inf;
p = t;
while (p! = s)
{
i = pre [p];
delta = min (delta, edge [i]. c);
p = edge [i]. from;
}
p = t;
while (p! = s)
{
i = pre [p];
edge [i]. c-= delta; edge [i ^ 1]. c + = delta;
p = edge [i]. from;
}
return delta * dist [t];
}
int mfmc ()
{
int ans = 0;
while (int delta = spfa ()) ans + = delta;
return ans;
}
int main ()
{
int i, j;
while (scanf ("% d% d% d% d", & n, & m, & k, & p)! = EOF)
{
cnt = 0;
memset (head, -1, sizeof (head));
s = 0; t = m + n +1;
for (i = 1; i <= n; i + +)
{
int tmp;
scanf ("% d", & tmp);
add (s, tmp, 1,0);
}
for (i = 1; i <= k; i + +)
{
int a, b, w;
scanf ("% d% d% d", & a, & b, & w);
add (a, b, inf, w); add (b, a, inf, w);
}
for (i = 1; i <= p; i + +)
{
int a, b, w;
scanf ("% d% d% d", & a, & b, & w);
add (b, m + a, inf, w);
}
for (i = 1; i <= n; i + +)
add (m + i, t, 1,0);
printf ("% d \ n", mfmc ());
}
return 0;
}
and hdoj compare test data and found several sets of data output wrong answer 0. But do not know what was wrong, and hope Daniel pointing
------ Solution ----------------------------- ---------------
ah I got it wrong ...... your code can handle a station multiple vessel situation. I'll look at the code
------ For reference only -------------------------------- -------
start a station to ensure that only one vessel?
------ For reference only -------------------------------------- -
it should be, not a few groups of test data are solvability
------ For reference only --------------- ------------------------
it should be, no test data sets, are solvable <> <>
there is no solution to this, and no relationship. The default map when you build a station only a vessel. I did not see a problem in the relevant narrative.
the way it is currently written spfa or take over a title previously code when the template? I now this spfa default code is correct, see your model built on the words wa also look at spfa code.
------ For reference only -------------------------------------- -
have found an error, is a template problem, ignoring the special circumstances augmenting path cost is 0
I've got the exercise on sun networking tutorial to work so now need to spend more time on how it works.
回复删除