• <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 閱讀(196) 評論(0)  編輯 收藏 引用
            精品久久久无码中文字幕| 久久精品国产福利国产秒| 久久男人中文字幕资源站| 亚洲精品综合久久| av无码久久久久久不卡网站| 久久精品国产一区二区三区| 91麻豆国产精品91久久久| 97久久香蕉国产线看观看| 久久精品一区二区影院| 久久香综合精品久久伊人| 欧美久久一区二区三区| 69久久精品无码一区二区| 久久只有这里有精品4| 久久本道久久综合伊人| 久久精品a亚洲国产v高清不卡| 亚洲欧洲精品成人久久曰影片| 久久96国产精品久久久| 人妻精品久久无码区| 久久精品这里只有精99品| 亚洲国产成人久久综合碰碰动漫3d| 久久人人爽人人爽人人片av麻烦| 国产精品99久久精品爆乳| 久久亚洲AV成人出白浆无码国产 | 久久精品亚洲福利| 波多野结衣中文字幕久久| 久久九九兔免费精品6| 伊人久久大香线蕉精品不卡| 国产—久久香蕉国产线看观看| 2021久久国自产拍精品| 国产精品久久久久影院嫩草| 久久香蕉超碰97国产精品 | 久久精品国产精品亚洲精品 | 久久综合给合综合久久| 久久www免费人成精品香蕉| 国产精品99久久不卡| 久久久艹| 久久人人爽人人爽人人片AV高清| 综合久久国产九一剧情麻豆 | 国产精品久久久久影院色| 欧美亚洲另类久久综合| 久久精品夜夜夜夜夜久久|