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

            superman

            聚精會神搞建設 一心一意謀發展
            posts - 190, comments - 17, trackbacks - 0, articles - 0
               :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            ZOJ 1268 - Is It A Tree?

            Posted on 2008-06-02 09:57 superman 閱讀(330) 評論(0)  編輯 收藏 引用 所屬分類: ZOJ
             1 /* Accepted 1268 C++ 00:00.00 840K */
             2 #include <iostream>
             3 
             4 using namespace std;
             5 
             6 int main()
             7 {
             8     int s, t, c = 1;
             9     while(true)
            10     {
            11         cin >> s >> t;
            12         if(s == -1 && t == -1)
            13             break;
            14         
            15         cout << "Case " << c++;
            16         
            17         if(s == 0 && t == 0)
            18         {
            19             cout << " is a tree." << endl;
            20             continue;
            21         }
            22         
            23         int cnt[2008= { 0 };
            24         bool x[2008= { false };
            25         
            26         x[s] = x[t] = true;
            27         int max = 0;
            28         max >?= s;
            29         max >?= t;
            30         
            31         cnt[t]++;
            32         while(cin >> s >> t && s && t)
            33             cnt[t]++, max >?= s, max >?= t, x[s] = x[t] = true;
            34         
            35         //count the number of roots
            36         int rootCnt = 0;
            37         for(int i = 1; i <= max; i++)
            38             if(x[i] && cnt[i] == 0)
            39                 rootCnt++;
            40         if(rootCnt != 1)
            41         {
            42             cout << " is not a tree." << endl;
            43             continue;
            44         }
            45         
            46         //check if each node has only one parent
            47         int i;
            48         for(i = 1; i <= max; i++)
            49             if(x[i] && cnt[i] > 1)
            50                 break;
            51         if(i <= max)
            52         {
            53             cout << " is not a tree." << endl;
            54             continue;
            55         }
            56         
            57         cout << " is a tree." << endl;
            58     }
            59     
            60     return 0;
            61 }
            62 
            亚洲av伊人久久综合密臀性色| 久久中文字幕无码专区| 一本色道久久99一综合| 久久精品国产日本波多野结衣| 久久国产精品无码HDAV| 精品免费久久久久国产一区 | 精品水蜜桃久久久久久久| 久久久WWW免费人成精品| 久久99热这里只有精品国产| 久久精品一本到99热免费| 久久久精品国产Sm最大网站| 亚洲色婷婷综合久久| 办公室久久精品| 久久久一本精品99久久精品88| 99国内精品久久久久久久| 久久免费看黄a级毛片| 久久99国产一区二区三区| 久久婷婷激情综合色综合俺也去| 久久男人AV资源网站| 久久久久久狠狠丁香| 亚洲欧美伊人久久综合一区二区| 久久久久九九精品影院| 高清免费久久午夜精品| 99久久国产亚洲综合精品| 久久99精品久久久久久9蜜桃| 99久久婷婷国产综合亚洲| 亚洲AV无一区二区三区久久| 亚洲国产一成久久精品国产成人综合 | 国产91久久精品一区二区| 精品久久人人爽天天玩人人妻| 久久人人爽人人爽人人片AV麻豆| 亚洲国产成人久久精品动漫| 久久99国产综合精品女同| 人妻丰满AV无码久久不卡| 久久九九久精品国产免费直播| 性做久久久久久久久老女人| 久久久久久A亚洲欧洲AV冫| 久久免费国产精品| 久久久久久久综合狠狠综合| 久久中文字幕精品| 婷婷久久久亚洲欧洲日产国码AV |