HDU 1869 (最短路)

两种最短路径算法的比较:

Dijkstra 算法的编码量是:1277B ,用时:46MS;

Floyd 算法的编码量是:808B ,用时:62MS;

#include 
#include 
#include 
using namespace std;
#define INF 0xffffff
#define max 105
int dist[max],map[max][max],n,m;
bool visited[max];
void Dijkstra (int s)
{
    int k=0;
    memset (visited,0,sizeof visited);
    for (int i=0;i>n >>m)
    {
        int a,b;
        for (int i=0;i>a >>b;
            map[a][b] = map[b][a] = 1;
        }
        bool tag = false;
        for (int i=0; i 7)
                {
                    tag = true;
                    break;
                }
            if (tag)
                break;
        }
        if (tag)
            puts ("No");
        else
            puts ("Yes");
    }
    return 0;
}


#include 
#define INF 0xffffff
#define max 101
int dist[max][max],n;
void Floyd ()
{
    for (int k=0;k dist[i][k]+dist[k][j])
                    dist[i][j] = dist[i][k]+dist[k][j];
}
void init ()
{
    for (int i=0;i 7)
                return false;
    return true;
}

int main ()
{
    int m;
    while (~scanf ("%d%d",&n,&m))
    {
        int a,b;
        init ();
        while (m--)
        {
            scanf ("%d%d",&a,&b);
            dist[a][b] = dist[b][a] = 1;
        }
        Floyd ();
        if (fun ())
            puts ("Yes");
        else
            puts ("No");
    }
    return 0;
}


你可能感兴趣的:(解题报告)