HDU 1853and3488 (Cyclic tour) and (tour) (Bipartite Graph)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.