A big copy of the world's questions, okay! Code 1853 just written! Then I found another bipartite graph question to do it. Check and erase it. Isn't it the same (that is, the input format is different )! So I have the courage to submit it. Okay! AC !!!
Small format changes! There is one question like this !!! Even the test instances are the same! Ah ·······
Although I have learned little about the bipartite graph for a long time, I have forgotten a little about it. Today, I have read the learning algorithms mentioned by others, so I must learn new things in a gentle manner, in the future, you must create more algorithms you have learned before! No ········
A simple binary chart is provided !!!
# Include <stdio. h>
# Include <string. h>
# Define INF 10000000
# Define max (A, B) A> B? A: B
# Define min (a, B) a <B? A: B
Int N;
Int match [1010], SX [1010], Sy [1010], map [1010] [1010], LX [1010], Ly [1010];
Int find (int K)
{
Int I;
SX [k] = 1;
For (I = 1; I <= N; I ++)
{
If (LX [k] + ly [I] = map [k] [I] & Sy [I] = 0)
{
Sy [I] = 1;
If (Match [I] = 0 | find (Match [I])
{
Match [I] = K;
Return 1;
}
}
}
Return 0;
}
Int km ()
{
Int I, J, K, ANS = 0;
Memset (match, 0, sizeof (MATCH ));
Memset (LX, 0, sizeof (LX ));
Memset (ly, 0, sizeof (ly ));
For (I = 1; I <= N; I ++)
For (j = 1; j <= N; j ++)
Lx [I] = max (LX [I], map [I] [J]);
For (I = 1; I <= N; I ++)
{
While (1)
{
Memset (sx, 0, sizeof (SX ));
Memset (SY, 0, sizeof (SY ));
If (find (I) break;
Else
{
Int A = inf;
For (j = 1; j <= N; j ++)
If (SX [J])
For (k = 1; k <= N; k ++)
If (! Sy [k])
A = min (A, LX [J] + ly [k]-map [J] [k]);
If (A = inf) return 1;
For (j = 1; j <= N; j ++)
{
If (SX [J]) lx [J]-=;
If (SY [J]) ly [J] + =;
}
}
}
}
For (I = 1; I <= N; I ++)
{
If (Map [Match [I] [I] =-INF)
Return 1;
If (Match [I]! = 0 & map [Match [I] [I]! =-INF)
Ans + = map [Match [I] [I];
}
Return ans;
}
Int main ()
{
Int M, I, j, V, U, W, ANS, T;
Scanf ("% d", & T );
While (t --)
{
Scanf ("% d", & N, & M );
For (I = 1; I <= N; I ++)
For (j = 1; j <= N; j ++)
Map [I] [J] =-INF;
For (I = 1; I <= m; I ++)
{
Scanf ("% d", & V, & U, & W );
If (-W> map [v] [u])
Map [v] [u] =-W;
}
Ans = km ();
Printf ("% d \ n",-ans );
}
Return 0;
}
Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 3488
Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1853