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

            聚精會(huì)神搞建設(shè) 一心一意謀發(fā)展
            posts - 190, comments - 17, trackbacks - 0, articles - 0
               :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            ZOJ 1268 - Is It A Tree?

            Posted on 2008-06-02 09:57 superman 閱讀(336) 評(píng)論(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 
            国产成年无码久久久免费| 国産精品久久久久久久| 无码伊人66久久大杳蕉网站谷歌| 2021国产精品午夜久久| 日本欧美久久久久免费播放网| 亚洲综合伊人久久综合| 久久91亚洲人成电影网站| 久久午夜福利电影| AAA级久久久精品无码片| 色婷婷狠狠久久综合五月| 国产亚洲欧美精品久久久| 中文成人无码精品久久久不卡| 精品久久久噜噜噜久久久| 日韩美女18网站久久精品| 91精品国产高清久久久久久io| 久久人人爽人人爽人人爽| 99久久伊人精品综合观看| 无码国内精品久久人妻蜜桃| 久久成人国产精品一区二区| 久久99热精品| 精品人妻久久久久久888| 日本强好片久久久久久AAA| 久久精品中文无码资源站| 午夜精品久久久内射近拍高清| 日韩精品久久久久久久电影| 97精品久久天干天天天按摩| 久久最新精品国产| 久久99国内精品自在现线| 久久夜色精品国产噜噜噜亚洲AV| 亚洲人成无码www久久久| 久久影院久久香蕉国产线看观看| 热re99久久6国产精品免费| 久久精品国产亚洲av麻豆蜜芽| 色婷婷久久久SWAG精品| 久久综合伊人77777麻豆| 欧美激情精品久久久久久久| 欧美精品福利视频一区二区三区久久久精品| 久久香蕉一级毛片| 久久久99精品成人片中文字幕| 欧美精品丝袜久久久中文字幕 | 7777久久亚洲中文字幕|