• <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 2457 Part Acquisition 寬搜

            用鄰接表存邊,需要記錄路徑。


            #include <stdio.h>

            #define MAX_N 50032
            #define MAX_K 1024

            struct queue_node {
                
            int step, idx;
                
            struct queue_node *prev;
            }
            ;
            struct queue_node queue[MAX_K];

            struct edge_node {
                
            int idx;
                
            struct edge_node *next;
            }
            ;
            struct edge_node edges[MAX_N], *map[MAX_K];

            int qh, qt, N, K, visited[MAX_K], path[MAX_K];

            __inline 
            int push(int idx, int step, struct queue_node *prev)
            {
                
            if (visited[idx])
                    
            return 0;
                visited[idx]
            ++;
                queue[qt].idx 
            = idx;
                queue[qt].step 
            = step;
                queue[qt].prev 
            = prev;
                qt
            ++;
                
            return idx == K;
            }


            int main()
            {
                
            int i, a, b;
                
            struct queue_node *t;
                
            struct edge_node *e;

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

                scanf(
            "%d%d"&N, &K);
                
            for (i = 0; i < N; i++{
                    scanf(
            "%d%d"&a, &b);
                    edges[i].idx 
            = b;
                    edges[i].next 
            = map[a];
                    map[a] 
            = &edges[i];
                }


                push(
            11, NULL);
                
            while (qh != qt) {
                    t 
            = &queue[qh++];
                    
            for (e = map[t->idx]; e; e = e->next) 
                        
            if (push(e->idx, t->step + 1, t))
                            
            break;
                    
            if (e)
                        
            break;
                }


                
            if (qh == qt) {
                    printf(
            "-1\n");
                    
            return 0;
                }


                t 
            = &queue[--qt];
                printf(
            "%d\n", t->step);
                
            for (i = 0; t; t = t->prev) 
                    path[i
            ++= t->idx;
                
            for (i--; i >= 0; i--)
                    printf(
            "%d\n", path[i]);

                
            return 0;
            }


            posted on 2010-03-31 17:14 糯米 閱讀(347) 評論(0)  編輯 收藏 引用 所屬分類: POJ

            久久精品一区二区三区中文字幕| 亚洲国产精品久久电影欧美| 欧美熟妇另类久久久久久不卡| 国产叼嘿久久精品久久| 久久er国产精品免费观看8| 99久久国产热无码精品免费久久久久 | 久久久久久久女国产乱让韩 | 久久亚洲日韩看片无码| 无码国内精品久久人妻| 成人精品一区二区久久久| 久久久网中文字幕| 久久免费的精品国产V∧| 久久国产高清字幕中文| 热RE99久久精品国产66热| 精品久久久久久成人AV| 久久久久18| 99精品国产在热久久| 一日本道伊人久久综合影| 2021久久国自产拍精品| 亚洲国产香蕉人人爽成AV片久久| 精品久久久久国产免费 | 国产69精品久久久久777| 久久综合九色欧美综合狠狠 | 欧美成a人片免费看久久| 韩国免费A级毛片久久| 亚洲精品无码久久毛片| 91精品国产色综久久| 久久99国内精品自在现线| 一本一本久久a久久综合精品蜜桃| 久久久久久无码Av成人影院| 欧美国产精品久久高清| 超级碰久久免费公开视频| 国产产无码乱码精品久久鸭| 久久久久国产精品嫩草影院| 亚洲欧美一级久久精品| 精品久久久久久无码人妻热| 久久777国产线看观看精品| 国产精品久久亚洲不卡动漫| 欧美噜噜久久久XXX| 麻豆成人久久精品二区三区免费| 久久久久黑人强伦姧人妻|