2013
12-12

# find the longest of the shortest

Marica is very angry with Mirko because he found a new girlfriend and she seeks revenge.Since she doesn’t live in the same city, she started preparing for the long journey.We know for every road how many minutes it takes to come from one city to another.
Mirko overheard in the car that one of the roads is under repairs, and that it is blocked, but didn’t konw exactly which road. It is possible to come from Marica’s city to Mirko’s no matter which road is closed.
Marica will travel only by non-blocked roads, and she will travel by shortest route. Mirko wants to know how long will it take for her to get to his city in the worst case, so that he could make sure that his girlfriend is out of town for long enough.Write a program that helps Mirko in finding out what is the longest time in minutes it could take for Marica to come by shortest route by non-blocked roads to his city.

Each case there are two numbers in the first row, N and M, separated by a single space, the number of towns,and the number of roads between the towns. 1 ≤ N ≤ 1000, 1 ≤ M ≤ N*(N-1)/2. The cities are markedwith numbers from 1 to N, Mirko is located in city 1, and Marica in city N.
In the next M lines are three numbers A, B and V, separated by commas. 1 ≤ A,B ≤ N, 1 ≤ V ≤ 1000.Those numbers mean that there is a two-way road between cities A and B, and that it is crossable in V minutes.

In the first line of the output file write the maximum time in minutes, it could take Marica to come to Mirko.

5 6
1 2 4
1 3 3
2 3 1
2 4 4
2 5 7
4 5 1

6 7
1 2 1
2 3 4
3 4 4
4 6 4
1 5 5
2 5 2
5 6 5

5 7
1 2 8
1 4 10
2 3 9
2 4 10
2 5 1
3 4 7
3 5 10

11
13
27

/*ID:cxlove
PROB:HDU 1595
DATA:2012.4.4
HINT:最短路径+枚举最短路径上的边
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#define inf 1<<30
using namespace std;
struct Node{
int u,v,w,next;
}edge[1000005];
struct EDGE{
int u,v,w,idx1,idx2;
}path[1005];
int start[1005],pre[1005],dist[1005];
int n,m,cnt,tot;
edge[cnt].u=u;edge[cnt].v=v;edge[cnt].w=w;
edge[cnt].next=start[u];start[u]=cnt++;
}
void Init(){
int u,v,w;
cnt=0;tot=0;
memset(start,-1,sizeof(start));
memset(pre,-1,sizeof(pre));
while(m--){
scanf("%d%d%d",&u,&v,&w);
}
}
void spfa(){
bool flag[1005];
for(int i=1;i<=n;i++)
dist[i]=inf;
memset(flag,false,sizeof(flag));
queue<int >que;
que.push(1);
flag[1]=true;
dist[1]=0;
while(!que.empty()){
int u=que.front();
que.pop();
flag[u]=false;
for(int i=start[u];i!=-1;i=edge[i].next){
int v=edge[i].v,w=edge[i].w;
if(dist[v]>dist[u]+w){
dist[v]=dist[u]+w;
pre[v]=u;
if(!flag[v]){
flag[v]=true;
que.push(v);
}
}
}
}
}
void find_path(){
int v=n;
while(pre[v]!=-1){
path[tot].u=pre[v];
path[tot].v=v;
path[tot].w=dist[v]-dist[pre[v]];
int k=start[pre[v]];
while(edge[k].v!=v)
k=edge[k].next;
path[tot].idx1=k;
k=start[v];
while(edge[k].v!=pre[v])
k=edge[k].next;
path[tot++].idx2=k;
v=pre[v];
}
}
void slove(){
int ans=0;
for(int i=0;i<tot;i++){
int idx1=path[i].idx1,idx2=path[i].idx2;
int t1=edge[idx1].w,t2=edge[idx2].w;
edge[idx1].w=inf;edge[idx2].w=inf;
spfa();
ans=max(ans,dist[n]);
edge[idx1].w=t1;edge[idx2].w=t2;
}
printf("%d\n",ans);
}
int main(){
while(scanf("%d%d",&n,&m)!=EOF){
Init();
spfa();;
find_path();
slove();
}
return 0;
}

1. #include <stdio.h>
int main(void)
{
int arr[] = {10,20,30,40,50,60};
int *p=arr;
printf("%d,%d,",*p++,*++p);
printf("%d,%d,%d",*p,*p++,*++p);
return 0;
}

为什么是 20,20,50,40,50. 我觉得的应该是 20,20,40,40,50 . 谁能解释下？

2. 你的理解应该是：即使主持人拿走一个箱子对结果没有影响。这样想，主持人拿走的箱子只是没有影响到你初始选择的那个箱子中有奖品的概率，但是改变了其余两个箱子的概率分布。由 1/3,1/3 变成了 0, 2/3

3. Excellent Web-site! I required to ask if I might webpages and use a component of the net web website and use a number of factors for just about any faculty process. Please notify me through email regardless of whether that would be excellent. Many thanks