• <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
            • 評論內容較長,點擊標題查看
            • --王私江
            7777久久亚洲中文字幕| 久久国产乱子伦精品免费午夜| 亚洲午夜久久久| 亚洲午夜福利精品久久| 久久久久av无码免费网| 久久99精品久久久久子伦| 久久精品视频免费| 大香伊人久久精品一区二区| 2021久久精品国产99国产精品| www久久久天天com| 久久大香萑太香蕉av| 国产麻豆精品久久一二三| 久久精品99无色码中文字幕| 亚洲国产另类久久久精品| 国产综合免费精品久久久| 久久99国产综合精品| 亚洲国产日韩综合久久精品| 免费观看久久精彩视频| 亚洲国产精品无码久久久秋霞2 | 精品久久久久久久| 久久综合成人网| 国产精品九九久久免费视频| 久久综合综合久久综合| 人人狠狠综合久久亚洲高清| 欧美精品一本久久男人的天堂| 久久99国产综合精品女同| 久久人人爽人人爽人人片AV高清| 久久久这里有精品中文字幕| 青青青国产成人久久111网站| 午夜欧美精品久久久久久久| 久久精品人妻中文系列| 国内精品久久久久影院老司| 亚洲一区精品伊人久久伊人| 天天影视色香欲综合久久| 久久影视综合亚洲| 一级做a爰片久久毛片免费陪| 亚洲国产成人久久笫一页| 青青久久精品国产免费看| 中文字幕无码久久人妻| 亚洲人成无码网站久久99热国产| 久久亚洲日韩看片无码|