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

            堅信:勤能補拙

            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 閱讀(199) 評論(0)  編輯 收藏 引用 所屬分類: R_找工復習2011

            導航

            <2010年10月>
            262728293012
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            統計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久久久国产精品嫩草影院| 久久久久久A亚洲欧洲AV冫| 久久精品国产AV一区二区三区| 久久久久久久久66精品片| 综合网日日天干夜夜久久| 色欲综合久久中文字幕网| 久久久久久综合一区中文字幕| 国产精品成人99久久久久91gav| 伊人久久国产免费观看视频| 无码人妻久久一区二区三区| 成人国内精品久久久久影院VR| 亚洲精品成人久久久| 精品永久久福利一区二区| 久久综合狠狠综合久久97色| 久久99国产精品久久久| 久久久久久伊人高潮影院| 亚洲国产成人久久精品动漫| 亚洲AV无码久久| 亚洲欧美国产日韩综合久久| 91精品国产91久久| 久久99精品久久久久久hb无码| 热99RE久久精品这里都是精品免费| 2021国产成人精品久久| 久久久久亚洲AV无码网站| 久久人人爽人爽人人爽av| 国产成人精品综合久久久| 国产一区二区精品久久| 亚洲精品国产字幕久久不卡| 思思久久99热只有频精品66| 久久最近最新中文字幕大全| 亚洲伊人久久成综合人影院| 精品国产热久久久福利| 久久久国产精品福利免费| 久久久一本精品99久久精品66| 亚洲欧洲精品成人久久曰影片 | 日日躁夜夜躁狠狠久久AV| 欧美亚洲国产精品久久久久| 久久综合九色欧美综合狠狠| 丁香五月综合久久激情| 久久精品国产免费一区| 久久精品国产亚洲欧美|