• <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 
            99麻豆久久久国产精品免费| 久久久久久久精品妇女99| 无码人妻久久久一区二区三区 | a高清免费毛片久久| 精品一区二区久久久久久久网站| 欧美777精品久久久久网| 久久伊人亚洲AV无码网站| 午夜天堂精品久久久久| 91精品国产色综合久久| 久久综合九色综合久99| 亚洲精品无码久久久久久| 亚洲伊人久久大香线蕉苏妲己| 久久一区二区三区99| 久久棈精品久久久久久噜噜| 久久艹国产| …久久精品99久久香蕉国产| 久久免费视频1| 97久久久久人妻精品专区 | 色婷婷噜噜久久国产精品12p | 99国产欧美久久久精品蜜芽| 久久精品国产一区二区电影| 久久天堂电影网| 国产精品中文久久久久久久| 91精品婷婷国产综合久久| 狠狠色狠狠色综合久久| 久久强奷乱码老熟女网站| 国产精品美女久久久| 久久久久亚洲AV成人片| 免费精品国产日韩热久久| 91精品国产色综久久| 91精品国产色综合久久| 久久久久久亚洲精品成人| 狠狠综合久久综合88亚洲 | 欧美精品国产综合久久| 日日狠狠久久偷偷色综合免费| 国产亚州精品女人久久久久久| 国产精品视频久久久| 久久亚洲精品中文字幕三区| 亚洲国产精品久久久久婷婷软件| 久久久国产乱子伦精品作者| 久久精品国产亚洲av水果派|