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

            糯米

            TI DaVinci, gstreamer, ffmpeg
            隨筆 - 167, 文章 - 0, 評論 - 47, 引用 - 0
            數據加載中……

            POJ 2394 Checking an Alibi 陰人題

            思路:

            就是一個最短路徑的問題。但是題目數據規模跟描述不符合。
            數組要開大一些才能過。官方數據是描述是符合的,可能是管理員加了一些進去。

            #include <stdio.h>
            #include 
            <string.h>
            #include 
            <stdlib.h>

            #define MAX_E 4096
            #define MAX_V 2048
            #define MAX_COST (1 << 30)

            struct edge_node {
                
            int idx, cost;
                
            struct edge_node *next;
            }
            ;

            struct graph_node {
                
            struct edge_node edges[MAX_E], *map[MAX_V];
                
            int edges_cnt, vertexs_cnt;
                
            int min_dis[MAX_V];
            }
            ;

            inline 
            int min(int a, int b)
            {
                
            return a < b ? a : b;
            }


            inline 
            void graph_init(struct graph_node *g, int vertexs_cnt)
            {
                g
            ->vertexs_cnt = vertexs_cnt;
                g
            ->edges_cnt = 0;
                memset(g
            ->map, 0, vertexs_cnt * sizeof(g->map[0]));
            }


            inline 
            void graph_addedge(struct graph_node *g, 
                                      
            int from, int to, 
                                      
            int cost
                                      )
            {
                
            struct edge_node *e;

                e 
            = &g->edges[g->edges_cnt++];
                e
            ->idx = to;
                e
            ->cost = cost;
                e
            ->next = g->map[from];
                g
            ->map[from] = e;
            }



            inline 
            void graph_spfa(struct graph_node *g, int idx)
            {
                
            static int queue[MAX_V], vis[MAX_V], tm, head, tail;
                
            int i, val;
                
            struct edge_node *e;

                
            for (i = 0; i < g->vertexs_cnt; i++)
                    g
            ->min_dis[i] = MAX_COST;
                g
            ->min_dis[idx] = 0;
                
                head 
            = tail = 0;
                tm
            ++;
                queue[tail
            ++= idx;

                
            while (head != tail) {
                    idx 
            = queue[head++];
                    vis[idx] 
            = 0;
                    
            for (e = g->map[idx]; e; e = e->next) {
                        val 
            = g->min_dis[idx] + e->cost;
                        
            if (val >= g->min_dis[e->idx])
                            
            continue;
                        g
            ->min_dis[e->idx] = val;
                        
            if (vis[e->idx] == tm) 
                            
            continue;
                        queue[tail
            ++= e->idx;
                        vis[e
            ->idx] = tm;
                    }

                }

            }


            int main()
            {
                
            static int loc[MAX_V], i, F, C, P, M, from, to, cost, cnt;
                
            static struct graph_node g;

                freopen(
            "e:\\test\\in.txt""r", stdin);

                scanf(
            "%d%d%d%d"&F, &P, &C, &M);
                graph_init(
            &g, F + 1);
                
            while (P--{
                    scanf(
            "%d%d%d"&from, &to, &cost);
                    graph_addedge(
            &g, from, to, cost);
                    graph_addedge(
            &g, to, from, cost);
                }

                
            for (i = 0; i < C; i++)
                    scanf(
            "%d"&loc[i]);

                graph_spfa(
            &g, 1);
                cnt 
            = 0;
                
            for (i = 0; i < C; i++)
                    cnt 
            += (g.min_dis[loc[i]] <= M);
                printf(
            "%d\n", cnt);
                
            for (i = 0; i < C; i++)
                    
            if (g.min_dis[loc[i]] <= M)
                        printf(
            "%d\n", i + 1);

                
            return 0;
            }

            posted on 2010-04-06 23:42 糯米 閱讀(382) 評論(1)  編輯 收藏 引用 所屬分類: POJ

            評論

            # re: POJ 2394 Checking an Alibi 陰人題[未登錄]  回復  更多評論   

            B哥越來越牛了
            2010-04-07 12:22 | yuyang
            77777亚洲午夜久久多喷| 亚洲欧洲中文日韩久久AV乱码| 国产精品美女久久久久网| 久久久中文字幕| 日日狠狠久久偷偷色综合96蜜桃| 久久精品国产亚洲AV久| 久久精品亚洲精品国产色婷| 国产精品一区二区久久精品无码| 99久久香蕉国产线看观香| 久久国产精品99国产精| 久久久久亚洲爆乳少妇无| 久久久亚洲欧洲日产国码aⅴ| 91亚洲国产成人久久精品| 久久久国产精华液| 日本久久久精品中文字幕| 99久久综合国产精品免费| 99久久夜色精品国产网站| 中文字幕无码精品亚洲资源网久久| 国产欧美久久久精品| 蜜桃麻豆WWW久久囤产精品| 亚洲国产精品久久久久婷婷软件| 久久综合九色综合网站| 一级做a爰片久久毛片16| 亚洲综合精品香蕉久久网| 久久婷婷人人澡人人| 91久久婷婷国产综合精品青草| 热久久最新网站获取| 国产精品亚洲综合专区片高清久久久| 久久亚洲春色中文字幕久久久| 色8激情欧美成人久久综合电| 久久亚洲高清观看| 热re99久久6国产精品免费| 欧美久久久久久午夜精品| 久久九九青青国产精品| 人妻精品久久久久中文字幕一冢本| 思思久久好好热精品国产| 久久综合狠狠综合久久97色| 66精品综合久久久久久久| 久久99国产综合精品| 亚洲欧美日韩中文久久 | 国产精品久久久久免费a∨|