C



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

Here is an example. In many cities in China, the government prohibit the middle school entrance examinations in order to relief studying burden of primary school students. Because there is no clear and strict standard of entrance, someone may make their children enter good middle schools through guanxis. Boss Liu wants to send his kid to a middle school by guanxi this year. So he find out his guanxi net. Boss Liu's guanxi net consists of N people including Boss Liu and the schoolmaster. In this net, two persons who has a guanxi between them can help each other. Because Boss Liu is a big money(In Chinese English, A "big money" means one who has a lot of money) and has little friends, his guanxi net is a naked money guanxi net -- it means that if there is a guanxi between A and B and A helps B, A must get paid. Through his guanxi net, Boss Liu may ask A to help him, then A may ask B for help, and then B may ask C for help ...... If the request finally reaches the schoolmaster, Boss Liu's kid will be accepted by the middle school. Of course, all helpers including the schoolmaster are paid by Boss Liu. 

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

For each test case: 

The first line contains two integers N and M. N means that there are N people in Boss Liu's guanxi net. They are numbered from 1 to N. Boss Liu is No. 1 and the schoolmaster is No. N. M means that there are M guanxis in Boss Liu's guanxi net. (3 <=N <= 30, 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 will be paid C RMB 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 do not try to undermine his plan.OutputFor each test case, output the minimum money Boss Liu has to spend after you have done your best. If Boss Liu will fail to send his kid to the middle school, print "Inf" instead.Sample Input
4 5
1 2 3
1 3 7
1 4 50
2 3 4
3 4 2
3 2
1 2 30
2 3 10
0 0
Sample Output
50
Inf

暴发户给孩子办关系升学,需要一个人找一个人,人情钱都是这货出,你要劝说其中一个人不去帮忙使得暴发户花钱最多。 又tm读错题了,你是劝说一个人使得他不去帮忙,而不是单纯的只使一个边变成inf!是与这个人相连的边都变成inf!还有就是虽说你想让这个人花钱最多,但是人家又不傻,当然会选择”最短路“来花钱!再有,总共30个点,枚举一遍怎么会超时 using namespace std; typedef long long ll; struct Node { ll v,w; bool operator<(const Node &t)const { return w>t.w; } Node(ll v1,ll w1) { v=v1,w=w1; } }; int visit[50]; ll d[50],n,m; ll G[50][50]; const ll maxn=0x3f3f3f3f3f3f3f3f; void init() { for(int i=1; i<=n; i++) d[i]=maxn; memset(visit,0,sizeof(visit)); } ll mark; void dijkstra() { d[1]=0; priority_queue<Node>que; que.push(Node(1,0)); while(que.size()) { Node a=que.top(); que.pop(); ll u=a.v; if(!visit[u]) visit[u]=1; else continue; for(ll i=1; i<=n; i++) if(G[u][i]&&i!=mark) { if(d[i]>d[u]+G[u][i]) { d[i]=d[u]+G[u][i]; que.push(Node(i,d[i])); } } } } int main() { while(~scanf("%lld%lld",&n,&m)&&n) { ll a,b,c; init(); memset(G,0,sizeof(G)); for(int i=0; i<m; i++) { scanf("%lld%lld%lld",&a,&b,&c); G[a][b]=G[b][a]=c; } ll ans=maxn; mark=-1;//一定要赋值为-1,否则出错 dijkstra(); ans=d[n]; // printf("----------%d----- ",ans); for(ll i=2; i<n; i++) { init(); mark=i; dijkstra(); ans=max(ans,d[n]); } if(ans>=maxn)printf("Inf "); else printf("%d ",ans); } return 0; }
"Guanxi" is a very important word in Chinese. It kind of means "relationship" or "contact". Guanxi can be based on friendship, but also can be built on money. So Chinese often say "I don't have one mao (0.1 RMB) guanxi with you." or "The guanxi between them is naked money guanxi." It is said that the Chinese society is a guanxi society, so you can see guanxi plays a very important role in many things. 

Here is an example. In many cities in China, the government prohibit the middle school entrance examinations in order to relief studying burden of primary school students. Because there is no clear and strict standard of entrance, someone may make their children enter good middle schools through guanxis. Boss Liu wants to send his kid to a middle school by guanxi this year. So he find out his guanxi net. Boss Liu's guanxi net consists of N people including Boss Liu and the schoolmaster. In this net, two persons who has a guanxi between them can help each other. Because Boss Liu is a big money(In Chinese English, A "big money" means one who has a lot of money) and has little friends, his guanxi net is a naked money guanxi net -- it means that if there is a guanxi between A and B and A helps B, A must get paid. Through his guanxi net, Boss Liu may ask A to help him, then A may ask B for help, and then B may ask C for help ...... If the request finally reaches the schoolmaster, Boss Liu's kid will be accepted by the middle school. Of course, all helpers including the schoolmaster are paid by Boss Liu. 

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

InputThere are several test cases. 

For each test case: 

The first line contains two integers N and M. N means that there are N people in Boss Liu's guanxi net. They are numbered from 1 to N. Boss Liu is No. 1 and the schoolmaster is No. N. M means that there are M guanxis in Boss Liu's guanxi net. (3 <=N <= 30, 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 will be paid C RMB 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 do not try to undermine his plan.OutputFor each test case, output the minimum money Boss Liu has to spend after you have done your best. If Boss Liu will fail to send his kid to the middle school, print "Inf" instead.Sample Input

4 5
1 2 3
1 3 7
1 4 50
2 3 4
3 4 2
3 2
1 2 30
2 3 10
0 0

Sample Output

50
Inf
原文地址:https://www.cnblogs.com/zhangzhenjun/p/11599785.html