How Many Maos Does the Guanxi Worth
How Many Maos Does the Guanxi Worth
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)
Total Submission(s): 864 Accepted Submission(s): 329
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.
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.
#include<stdio.h>
#include<string.h>
#define MAX(x,y)(x>y?x:y)
const int INF=0x3f3f3f3f;
const int MAXN=;
int N;
int d[MAXN],vis[MAXN];
int map[MAXN][MAXN],num[MAXN];
void initial(){
for(int i=;i<=N;i++){
d[i]=-INF;
}
memset(vis,,sizeof(vis));
}
struct Node{
int s,e,dis;
};
Node dt[];
void dijskra(int s){
initial();
d[s]=;
while(true){
int k=-;
for(int i=;i<=N;i++)
if(!vis[i]&&(k==-||d[i]>d[k]))k=i;
if(k==-)break;
vis[k]=;
for(int i=;i<=N;i++)
d[i]=MAX(d[i],d[k]+map[k][i]);
}
}
int main(){
int M,a,b,c;
while(~scanf("%d%d",&N,&M),N||M){
for(int i=;i<M;i++){
scanf("%d%d%d",&dt[i].s,&dt[i].e,&dt[i].dis);
}int temp=,t,ans=,answer=;
for(t=;t<N;t++){
for(int i=;i<=N;i++){
for(int j=;j<=N;j++){
map[i][j]=-INF;
}
}
for(int i=;i<M;i++){
map[dt[i].s][dt[i].e]=map[dt[i].e][dt[i].s]=dt[i].dis;
}
// printf("t=%d\n",t);
for(int i=;i<=N;i++){
map[t][i]=map[i][t]=-INF;
}
dijskra();
if(d[N]==-INF){
ans=;
break;
}
answer=MAX(answer,d[N]);
}
if(ans)printf("%d\n",answer);
else puts("Inf");
}
return ;}
How Many Maos Does the Guanxi Worth的更多相关文章
- hdu 5137 How Many Maos Does the Guanxi Worth 最短路 spfa
How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/5 ...
- HDU 5137 How Many Maos Does the Guanxi Worth
How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/5120 ...
- hdoj 5137 How Many Maos Does the Guanxi Worth【最短路枚举+删边】
How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/5 ...
- HDU5137 How Many Maos Does the Guanxi Worth(枚举+dijkstra)
How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/5 ...
- HDU 5137 How Many Maos Does the Guanxi Worth 最短路 dijkstra
How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/5 ...
- (hdoj 5137 floyd)How Many Maos Does the Guanxi Worth
How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/5 ...
- 杭电5137How Many Maos Does the Guanxi Worth
How Many Maos Does the Guanxi Worth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/5 ...
- ACM学习历程——HDU5137 How Many Maos Does the Guanxi Worth(14广州10题)(单源最短路)
Problem Description "Guanxi" is a very important word in Chinese. It kind of means &quo ...
- UVALive 7079 - How Many Maos Does the Guanxi Worth(最短路Floyd)
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...
随机推荐
- 一步一步学python(七) - 更加抽象
1.面向对象 面向对象程序设计中的术语对象基本上可以看做数据以及由一系列可以存取这些数据方法所组成的集合. 2.多态 对不同的类的对象使用同样的操作 2.1 多态和方法 程序得到了对象可能有多种形状, ...
- Unix/Linux环境C编程入门教程(21) 各个系统HelloWorld跑起来效果如何?
Unix/Linux家族人员众多,我们无法一一讲解如何配置环境. 本文选定我们在前面安装的RHEL6 RHEL7 MAC10.9.3 Solaris11如何跑起来helloworld RHEL 6 上 ...
- GPS功能:百度路书自定义【轨迹回放】
如题所述:百度的编辑界面很直观,修改后就可以运行,地址:http://developer.baidu.com/map/jsdemo.htm#c2_8: 因为同事研究了一下午结果都没搞出来,他copy百 ...
- linux之SQL语句简明教程---SELECT
SQL是用来做什么的呢?一个最常用的方式是将资料从数据库中的表格内选出.从这一句回答中,我们马上可以看到两个关键字: 从 (FROM) 数据库中的表格内 选出 (SELECT).(表格是一个数据库内的 ...
- 电子科大POJ "敲错键盘"
C-sources: #include<stdio.h> #define N 20 int main() { int i,j; ]={'Q','W','E','R','T','Y','U' ...
- API经济产业
技术大咖为我们铺好了前进道路,我们为什么还要敬而远之舍近索远呢?充分利用开源,利用API进行App有效整合. 为应用添加日志功能,Loggly; 为应用添加用户管理和身份认证模块,Stormpath; ...
- 窥探 kernel --- 进程调度的目标,nice值,静态优先级,动态优先级,实时优先级
http://blog.chinaunix.net/uid-24227137-id-3595610.html 窥探 kernel --- 进程调度的目标,nice值,静态优先级,动态优先级,实时优先级 ...
- Hadoop 4、Hadoop MapReduce的工作原理
一.MapReduce的概念 MapReduce是hadoop的核心组件之一,hadoop要分布式包括两部分,一是分布式文件系统hdfs,一部是分布式计算框就是mapreduce,两者缺一不可,也就是 ...
- Minimum Sum(思维)
Problem 1603 - Minimum Sum Time Limit: 2000MS Memory Limit: 65536KB Total Submit: 563 Accepted ...
- 充分利用HTML标签元素 – 简单的xtyle前端框架
xtyle框架充分利用语义化标签来做美化样式,兼容多款主流浏览器,包括IE8. xtyle框架虽然没BS这么强大,但我觉得也很实用,体积不算很大,适用于企业网站.WordPress主题.个人网站.博客 ...