HDU 1595 find the longest of the shortest

find the longest of the shortest

Problem Description
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.
 

Input
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.
 

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

Sample Input
 
   
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
 
Sample Output
 
   
11 13 27

题意:输入还是普通的最短路输入,点和权值,其中有一段路径是坏的,但是不知道是那一条路,现在以最短路走,求出最坏的一种情况下的最短路,也就是所有可能性里最长的最短路。


先考虑正常情况下的最短路,断路一定在最短路上才可以影响最终的结果,所以要记住第一次的路径,然后逐个删去求最短路。

#include
#include
#include
#include
#define M 0xfffffff;
using namespace std;
int n,m;
int map[1002][1002];
int vis[1002];
int backto[10002],rlist[500002],rlist1[500002];
int e,minm;

void bfs()
{
    int i;
    minm=M;
    e=0;
    memset(vis,-1,sizeof(vis));
    queueq;
    int front;
    front=1;
    vis[1]=0;
    q.push(front);
    memset(backto,0,sizeof(backto));
    while(!q.empty())
    {
        front=q.front();
        q.pop();
        for(i=1; i<=n; i++)
        {
            if(map[front][i]>0&&(vis[front]+map[front][i]=0)
                map[j][k]=min(map[j][k],l);
            else
                map[j][k]=l;
            map[k][j]=map[j][k];
        }
        bfs();
        goback();

        int badr=0;
        for(i=0; ibadr)
            {
                badr=minm;
            }
            map[k][j]=l;map[j][k]=l;
        }
        printf("%d\n",badr);
    }
    return 0;
}




你可能感兴趣的:(ACM,图论,(搜索)记忆化搜索)