• <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日韩AV天堂久久| 99久久精品久久久久久清纯| 一本色道久久88综合日韩精品 | 久久亚洲AV无码精品色午夜 | 久久综合亚洲色HEZYO社区| 亚洲AV成人无码久久精品老人| 久久不射电影网| 午夜精品久久久久久影视riav| 狠狠色综合久久久久尤物| 国产一久久香蕉国产线看观看| 精品国产乱码久久久久久浪潮 | 欧美亚洲色综久久精品国产| 国产精品美女久久福利网站| 狠狠久久亚洲欧美专区| 亚洲午夜久久久久久噜噜噜| 亚洲精品美女久久777777| 国产福利电影一区二区三区久久久久成人精品综合 | 伊人久久国产免费观看视频| 久久91精品国产91久久户| 久久亚洲AV无码精品色午夜| 久久五月精品中文字幕| 国产亚洲精午夜久久久久久 | 日本国产精品久久| 欧美激情精品久久久久久久九九九 | jizzjizz国产精品久久| 99久久er这里只有精品18| 久久久久av无码免费网| 精品多毛少妇人妻AV免费久久| 国产激情久久久久影院老熟女| 久久精品毛片免费观看| 99久久免费只有精品国产| 久久久久99精品成人片直播| 99精品久久精品一区二区| 久久亚洲精品国产精品婷婷| 日韩电影久久久被窝网| 亚洲国产成人精品女人久久久| 欧美日韩成人精品久久久免费看| 亚洲国产精品久久久久网站 | 久久久WWW成人免费毛片| 国产精品美女久久福利网站|