• <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)  編輯 收藏 引用
            久久亚洲欧洲国产综合| 久久无码人妻精品一区二区三区| 久久人人爽人人爽人人片AV麻豆| 成人午夜精品久久久久久久小说| 国产精品免费福利久久| 久久久久久毛片免费看| 男女久久久国产一区二区三区| 人人狠狠综合久久88成人| 丁香五月综合久久激情| 欧美与黑人午夜性猛交久久久| 久久精品国产清自在天天线| 精品久久久久久国产| 久久精品国产亚洲av麻豆图片| 99久久综合狠狠综合久久| 亚洲va久久久噜噜噜久久狠狠| 99久久精品免费国产大片| 精品多毛少妇人妻AV免费久久| 久久亚洲国产精品五月天婷| 99热成人精品热久久669| 亚洲国产精品久久久天堂| 久久国产劲爆AV内射—百度| 久久亚洲中文字幕精品一区| 精品久久人人妻人人做精品| 久久精品中文字幕有码| 欧美日韩精品久久久免费观看| 四虎影视久久久免费观看| 久久夜色精品国产亚洲| 久久一日本道色综合久久| 久久精品人人做人人爽电影| 久久天天躁狠狠躁夜夜2020老熟妇| 久久久亚洲精品蜜桃臀| 久久久久久精品久久久久| 久久亚洲中文字幕精品有坂深雪| 久久无码人妻一区二区三区午夜| 97久久久精品综合88久久| 99久久综合国产精品免费| 91精品国产9l久久久久| 久久久久久久久久久精品尤物| 久久久无码人妻精品无码| 久久人妻少妇嫩草AV无码蜜桃| 久久亚洲AV成人出白浆无码国产|