HDU 5137 How many Maos Does the Guanxi Worth (14 guangzhou Floyd shortest circuit)

Source: Internet
Author: User


How many Maos Does the Guanxi Worth Time limit:2000/1000 MS (java/others) Memory limit:512000/512000 K (java/others) Total Submission (s): 468 Accepted Submission (s): 164

problem Description"Guanxi" is a very important word in Chinese. It kind of means "relationship" or "contact". Guanxi can is based on friendship, but also can is built on money. So Chinese often say "I don ' t has one Mao (0.1 RMB) guanxi with you." or "the guanxi between them was naked money guanxi." It is said that the Chinese society are a guanxi society so can see guanxi plays a very important role in many things .

Here's an example. In many cities in China, the government prohibit the middle school entrance examinations in order to relief studying Burde N of primary school students. Because there is no clear and strict standard of entrance, someone could make their children enter good middle schools throu GH Guanxis. Boss Liu wants to send he kid to a middle school by guanxi this year. So he and find out his guanxi net. Boss Liu ' s guanxi net consists of N people including Boss Liu and the schoolmaster. In this net, the persons who have a guanxi between them can help each other. Because Boss Liu is a big money (in Chinese 中文版, a "big money" means one who had a lot of money) and have little friends , his guanxi net was a naked money guanxi net--it means so if there is a guanxi between A and B and a helps B, a must g ET paid. Through his guanxi net, Boss Liu could ask a to help him, then a could ask B for help, and then B could ask C for help ... If the request finally reaches the schoolmaster, Boss Liu ' s Kid'll is accepted by the middle school. Of course, all helpers including the schoolmaster is paid by Boss Liu.

You hate boss Liu and your want to undermine boss Liu ' s plan. All the can do are to persuade a person in Boss Liu's guanxi net to reject any request. This person can is any one, but can ' t be Boss Liu or the schoolmaster. If you can ' t do boss Liu fail, you want boss Liu to spend as much money as possible. You should figure out this after you had done your best, how much at least must Boss Liu spend to get what he wants. Please note this if you do nothing, Boss Liu'll definitely succeed. 
InputThere is several test cases.

For each test case:

The first line contains the integers n and M. N means that there is n people in Boss Liu ' s guanxi net. They is numbered from 1 to N. Boss Liu is no. 1 and the schoolmaster is No. N. m means that there be M guanxis in Boss L IU ' s guanxi net. (3 <=n <= 3 <= M <= 1000)

Then M lines follow. Each line contains three integers a, B and C, meaning that there is a guanxi between A and B, and if A asks B or B asks a For help, the helper would be paid C $ by Boss Liu.

The input ends with N = 0 and M = 0.

It's guaranteed that Boss Liu's request can reach the schoolmaster if you don't try to undermine his plan. 
Outputfor each test case, the output of the minimum money Boss Liu had to spend after you had done your best. If Boss Liu would fail to send his kid to the middle school, print "INF" instead. 
Sample Input
4 51 2 31 3 71 4 502 3 43 4 23 21 2 302 3 100 0
 
Sample Output
50Inf
 
Source2014ACM/ICPC Asia Guangzhou Station-re-match (thanks to Chinese laborers and PKU)


Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5137

Title: Give a weighted graph n points, M edge, ask to remove the maximum value of the shortest path except for the 1th and nth points, if not, the output inf

Title Analysis: This problem because the data volume is not big, can use Floyd do, with Floyd do very convenient, each delete point only need to set the value of the association edge to the INF and then find the shortest possible, and finally take a maximum value

#include <cstdio> #include <cstring> #include <algorithm>using namespace std;int const MAX = 35;int        Const INF = 0x3fffffff;int N, m;int Map[max][max], d[max][max];int Floyd (int x) {for (int i = 1; I <= n; i++)            for (int j = 1; J <= N; j + +) if (i = = x | | j = = x) d[i][j] = d[j][i] = INF;    else d[i][j] = d[j][i] = Map[i][j];                 for (int k = 1, k <= N; k++) for (int i = 1; I <= n; i++) for (int j = 1; J <= N; j + +)    D[i][j] = min (D[i][j], d[i][k] + d[k][j]); return d[1][n];}        int main () {while (scanf ("%d%d", &n, &m)! = EOF && (n + m)) {int U, V, W;        for (int i = 1, i <= N; i++) for (int j = 1; J <= N; j + +) Map[i][j] = (i = = J 0:inf);            for (int i = 0; i < m; i++) {scanf ("%d%d%d", &u, &v, &w);    if (Map[u][v] > W) map[u][v] = W;         Map[v][u] = Map[u][v];        } int ans = 0;        for (int i = 2; i < n; i++) ans = max (ans, Floyd (i));        if (ans = = INF) printf ("inf\n");    else printf ("%d\n", ans); }}


HDU 5137 How many Maos Does the Guanxi Worth (14 guangzhou Floyd shortest circuit)

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.