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

            A Za, A Za, Fighting...

            堅(jiān)信:勤能補(bǔ)拙

            2011搜索-題,DFS,沿路徑搜索

            代碼:
            #include<stdio.h>
            #include
            <stdlib.h>
            #include
            <string.h>
            #define MAX_K 101
            #define MAX_N 1001
            char matrix[MAX_N][MAX_N];
            char visited[MAX_N];
            short count[MAX_N];
            int pastures[MAX_K];

            int K, N, M;

            void
            dfs(
            int pasture)
            {
                
            int i;
                
            ++count[pasture];
                visited[pasture] 
            = 1;
                
            for(i=1; i<=N; ++i) {
                    
            if(matrix[pasture][i] && !visited[i])
                        dfs(i);
                }
            }

            int
            main(
            int argc, char **argv)
            {
                
            int i, x, y, ret = 0;
                scanf(
            "%d %d %d"&K, &N, &M);
                
            for(i=1; i<=K; ++i)
                    scanf(
            "%d", pastures+i);
                
            for(i=1; i<=M; ++i) {
                    scanf(
            "%d %d"&x, &y);
                    matrix[x][y] 
            = 1;
                }
                
                
            for(i=1; i<=K; ++i) {
                    memset(visited, 
            0sizeof(visited));
                    dfs(pastures[i]);
                }

                
            for(i=1; i<=N; ++i)
                    
            if(count[i] == K)
                        
            ++ret;
                printf(
            "%d\n", ret);
            }


            Cow Picnic
            Time Limit: 2000MSMemory Limit: 65536K
            Total Submissions: 3878Accepted: 1576

            Description

            The cows are having a picnic! Each of Farmer John's K (1 ≤ K ≤ 100) cows is grazing in one of N (1 ≤ N ≤ 1,000) pastures, conveniently numbered 1...N. The pastures are connected by M (1 ≤ M ≤ 10,000) one-way paths (no path connects a pasture to itself).

            The cows want to gather in the same pasture for their picnic, but (because of the one-way paths) some cows may only be able to get to some pastures. Help the cows out by figuring out how many pastures are reachable by all cows, and hence are possible picnic locations.

            Input

            Line 1: Three space-separated integers, respectively: KN, and M 
            Lines 2..K+1: Line i+1 contains a single integer (1..N) which is the number of the pasture in which cow i is grazing. 
            Lines K+2..M+K+1: Each line contains two space-separated integers, respectively A and B (both 1..N and A != B), representing a one-way path from pasture A to pasture B.

            Output

            Line 1: The single integer that is the number of pastures that are reachable by all cows via the one-way paths.

            Sample Input

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

            Sample Output

            2

            Hint

            The cows can meet in pastures 3 or 4.

            Source






            posted on 2011-08-15 16:13 simplyzhao 閱讀(202) 評(píng)論(0)  編輯 收藏 引用 所屬分類: R_找工復(fù)習(xí)2011

            導(dǎo)航

            <2010年6月>
            303112345
            6789101112
            13141516171819
            20212223242526
            27282930123
            45678910

            統(tǒng)計(jì)

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            66精品综合久久久久久久| 国内精品九九久久精品| 国产午夜精品久久久久免费视| 精品久久久无码人妻中文字幕| 亚洲va中文字幕无码久久不卡| 久久久精品人妻一区二区三区蜜桃 | 麻豆精品久久久久久久99蜜桃 | 久久棈精品久久久久久噜噜| 国产高潮国产高潮久久久| 狠狠人妻久久久久久综合| 久久综合九色综合网站| 久久精品中文字幕久久| 麻豆精品久久久久久久99蜜桃| AV无码久久久久不卡网站下载 | yy6080久久| 久久亚洲综合色一区二区三区| 女人高潮久久久叫人喷水| 91精品国产色综久久| 久久久精品2019免费观看| 久久精品国产亚洲精品| 久久一日本道色综合久久| 午夜精品久久久久久| 精品久久久久久国产牛牛app| 亚洲AV无码一区东京热久久| 蜜桃麻豆www久久国产精品| 大美女久久久久久j久久| 韩国三级大全久久网站| 亚洲欧美日韩中文久久| 久久亚洲国产最新网站| 久久久久18| 久久乐国产精品亚洲综合| 青青草原综合久久| 久久99免费视频| 亚洲国产精品婷婷久久| 久久福利青草精品资源站免费| 国内精品人妻无码久久久影院导航 | 青青草原1769久久免费播放| 久久亚洲国产午夜精品理论片| 国产精品一久久香蕉国产线看观看 | 久久婷婷五月综合国产尤物app| 久久久久青草线蕉综合超碰|