• <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>

            poj3259

            Wormholes

            Time Limit: 2000MS Memory Limit: 65536K
            Total Submissions: 16899 Accepted: 5961

            Description

            While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a time that is BEFORE you entered the wormhole! Each of FJ's farms comprises N (1 ≤ N ≤ 500) fields conveniently numbered 1..N, M (1 ≤ M ≤ 2500) paths, and W (1 ≤ W ≤ 200) wormholes.

            As FJ is an avid time-traveling fan, he wants to do the following: start at some field, travel through some paths and wormholes, and return to the starting field a time before his initial departure. Perhaps he will be able to meet himself :) .

            To help FJ find out whether this is possible or not, he will supply you with complete maps to F (1 ≤ F ≤ 5) of his farms. No paths will take longer than 10,000 seconds to travel and no wormhole can bring FJ back in time by more than 10,000 seconds.

            Input

            Line 1: A single integer, F. F farm descriptions follow.
            Line 1 of each farm: Three space-separated integers respectively: N, M, and W
            Lines 2..M+1 of each farm: Three space-separated numbers (S, E, T) that describe, respectively: a bidirectional path between S and E that requires T seconds to traverse. Two fields might be connected by more than one path.
            Lines M+2..M+W+1 of each farm: Three space-separated numbers (S, E, T) that describe, respectively: A one way path from S to E that also moves the traveler back T seconds.

            Output

            Lines 1..F: For each farm, output "YES" if FJ can achieve his goal, otherwise output "NO" (do not include the quotes).

            Sample Input

            2
            3 3 1
            1 2 2
            1 3 4
            2 3 1
            3 1 3
            3 2 1
            1 2 3
            2 3 4
            3 1 8

            Sample Output

            NO
            YES
            這個題跟poj1860,poj2240本質是一樣的,都是求有無負權回路
            構圖時候把每個蟲洞的邊的邊值w存為-w,注意普通路徑是雙向邊
            bellford求負權回路原理:如果無向圖邊上存在負權回路,則回路邊上的邊(u,v)的d[v]值一定小于d[u]+w[u,v]。
            如果寫spfa的話,記下每個節點的入隊次數,如果某個節點的入隊次數超過n次的話,就說明存在負權回路
            其實我是各種不明白……
             1#include<stdio.h>
             2#include<string.h>
             3#include<math.h>
             4#define MAX 30000
             5struct node
             6{
             7    int h1,t1,len;
             8}
            ;
             9struct node bb[MAX+5];
            10int s,d[1000];
            11int n,m,w;
            12void init()
            13{
            14    int a,b,c;
            15    int i;
            16    s=0;
            17    memset(bb,0,sizeof(bb));
            18    scanf("%d%d%d",&n,&m,&w);
            19    for (i=1; i<=m ; i++ )
            20    {
            21        scanf("%d%d%d",&a,&b,&c);
            22        s++;
            23        bb[s].h1=a;
            24        bb[s].t1=b;
            25        bb[s].len=c;
            26        s++;
            27        bb[s].h1=b;
            28        bb[s].t1=a;
            29        bb[s].len=c;
            30    }

            31    for (i=1; i<=w ; i++ )
            32    {
            33        scanf("%d%d%d",&a,&b,&c);
            34        s++;
            35        bb[s].h1=a;
            36        bb[s].t1=b;
            37        bb[s].len=-c;
            38    }

            39}

            40void bellman_ford()
            41{
            42    int i,j,flag;
            43    memset(d,0,sizeof(d));
            44    for (i=1; i<=n; i++)
            45    {
            46        flag=0;
            47        for (j=1; j<=s; j++)
            48            if (d[bb[j].h1]+bb[j].len<d[bb[j].t1])
            49            {
            50                d[bb[j].t1]=d[bb[j].h1]+bb[j].len;
            51            }

            52    }

            53    //////找有無負權回路
            54    for (i=1; i<=s ; i++ )
            55        if (d[bb[i].h1]+bb[i].len<d[bb[i].t1])
            56        {
            57            printf("YES\n");
            58            return;
            59        }

            60    printf("NO\n");
            61}

            62int main()
            63{
            64    int t;
            65    scanf("%d",&t);
            66    while (t>0)
            67    {
            68        init();
            69        bellman_ford();
            70        t--;
            71    }

            72    return 0;
            73}

            74

            posted on 2012-02-13 23:15 jh818012 閱讀(320) 評論(0)  編輯 收藏 引用

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導航

            統計

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當于是 取余3的意思 因為 3 的 二進制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄]
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評論內容較長,點擊標題查看
            • --王私江
            久久国产精品99国产精| 韩国三级中文字幕hd久久精品| 综合久久久久久中文字幕亚洲国产国产综合一区首| 四虎国产精品免费久久久| 久久久精品国产Sm最大网站| 亚洲精品视频久久久| 国产午夜精品久久久久免费视| 久久国产精品-久久精品| 一本综合久久国产二区| 国产国产成人精品久久| 亚洲国产精品无码久久久久久曰| 欧洲精品久久久av无码电影| 久久久久国产一区二区| 日韩av无码久久精品免费| 久久精品成人免费国产片小草| 无码国内精品久久人妻蜜桃| 久久久久久国产精品无码下载 | 久久中文娱乐网| 亚洲七七久久精品中文国产 | 久久成人永久免费播放| 国产偷久久久精品专区| 久久免费99精品国产自在现线 | 久久这里只精品99re66| 久久精品国产免费一区| 性欧美大战久久久久久久久| 久久免费国产精品| 久久AⅤ人妻少妇嫩草影院| 国产91色综合久久免费| 久久精品国产亚洲av麻豆小说 | 久久精品国产亚洲Aⅴ香蕉| 久久被窝电影亚洲爽爽爽| 亚洲AV日韩精品久久久久久久| 一本一道久久a久久精品综合| 久久影院久久香蕉国产线看观看| 99久久国产免费福利| 日韩精品久久久久久| 99热成人精品免费久久| 99久久精品国产毛片| 国产99久久久久久免费看| 国产精品99久久久久久www| 99久久精品无码一区二区毛片|