• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 100,  comments - 15,  trackbacks - 0
             1#include <limits.h>
             2#include <stdio.h>
             3#include <stdlib.h>
             4
             5/* Let INFINITY be an integer value not likely to be
             6   confused with a real weight, even a negative one. */

             7#define INFINITY ((1 << 14)-1)
             8
             9typedef struct {
            10    int source;
            11    int dest;
            12    int weight;
            13}
             Edge;
            14
            15void BellmanFord(Edge edges[], int edgecount, int nodecount, int source)
            16{
            17    int *distance = (int*) malloc (nodecount * sizeof (*distance));    //int
            18    int i, j;
            19
            20    for (i=0; i < nodecount; ++i)
            21      distance[i] = INFINITY;
            22    distance[source] = 0;
            23
            24    for (i=0; i < nodecount; ++i) 
            25    {
            26       int somethingchanged = 0
            27       for (j=0; j < edgecount; ++j) 
            28       {
            29            if (distance[edges[j].source] != INFINITY) 
            30            {
            31                int new_distance = distance[edges[j].source] + edges[j].weight;
            32                if (new_distance < distance[edges[j].dest])
            33                {
            34                  distance[edges[j].dest] = new_distance;
            35                  somethingchanged = 1;
            36                }
             
            37            }

            38        }

            39        /* if one iteration had no effect, further iterations will have no effect either */
            40        if (!somethingchanged) break;
            41    }

            42
            43    for (i=0; i < edgecount; ++i) 
            44    {
            45        if (distance[edges[i].dest] > distance[edges[i].source] + edges[i].weight) 
            46        {
            47            puts("Negative edge weight cycles detected!");
            48            free(distance);
            49            return;
            50        }

            51    }

            52
            53    for (i=0; i < nodecount; ++i) {
            54        printf("The shortest distance between nodes %d and %d is %d\n",
            55            source, i, distance[i]);
            56    }

            57
            58    free(distance);
            59    return;
            60}

            61
            62int main(void)
            63{
            64    /* This test case should produce the distances 2, 4, 7, -2, and 0. */
            65    Edge edges[10= {{0,15}{0,28}{0,3-4}{1,0-2},
            66                      {2,1-3}{2,39}{3,17}{3,42},
            67                      {4,06}{4,27}}
            ;
            68    BellmanFord(edges, 1054);
            69    return 0;
            70}

            71
            posted on 2009-04-03 22:08 wyiu 閱讀(194) 評論(0)  編輯 收藏 引用
            99久久99久久精品国产片果冻 | 久久99热精品| 国产精品久久久久9999高清| 日本精品久久久久中文字幕8| 天天久久狠狠色综合| 亚洲精品午夜国产va久久| 久久无码人妻一区二区三区午夜 | 久久人人爽人人爽人人片AV麻豆 | 亚洲精品无码成人片久久| 久久精品视频免费| 久久精品综合网| 很黄很污的网站久久mimi色| 久久精品国产男包| 国产福利电影一区二区三区,免费久久久久久久精 | 久久精品国产亚洲av影院| 91久久精品视频| 欧洲成人午夜精品无码区久久| 国产精品美女久久久免费| 久久亚洲精品成人av无码网站| 久久免费香蕉视频| 伊人久久大香线焦综合四虎| 亚洲av伊人久久综合密臀性色| 久久这里只有精品视频99| 久久综合综合久久97色| 久久久无码精品亚洲日韩蜜臀浪潮| 久久综合五月丁香久久激情| 久久777国产线看观看精品| 色狠狠久久AV五月综合| 久久婷婷国产剧情内射白浆| 欧美激情精品久久久久久久| 国产精品无码久久久久| 国产精久久一区二区三区| 久久美女网站免费| 色综合久久中文综合网| 国产成人精品免费久久久久| 久久国产精品一国产精品金尊 | 久久精品aⅴ无码中文字字幕不卡 久久精品成人欧美大片 | 欧美粉嫩小泬久久久久久久| 久久综合色之久久综合| 麻豆久久久9性大片| 女人高潮久久久叫人喷水|