• <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 閱讀(330) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): 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 
            国产999精品久久久久久| 久久久久久曰本AV免费免费| 97久久精品国产精品青草| www久久久天天com| 久久国产成人精品国产成人亚洲| 日本高清无卡码一区二区久久| 久久综合亚洲色HEZYO国产 | 久久久久亚洲AV片无码下载蜜桃| 性做久久久久久久| 久久综合狠狠综合久久激情 | 久久亚洲国产成人精品无码区| 国产亚洲精品久久久久秋霞| 四虎国产精品免费久久久| 亚洲精品乱码久久久久久不卡| 91久久精品91久久性色| 久久午夜综合久久| 国产精品久久久久久久久免费| 亚洲а∨天堂久久精品9966| 久久99免费视频| 无码人妻久久一区二区三区蜜桃| 一本久久a久久精品综合夜夜| 亚洲精品tv久久久久| 丁香五月综合久久激情| 7777久久亚洲中文字幕| 色妞色综合久久夜夜| 午夜精品久久久久成人| 久久精品18| 国内精品久久久久久久涩爱| 久久青青草原国产精品免费| 久久精品无码一区二区WWW| 热综合一本伊人久久精品| 国产精品欧美亚洲韩国日本久久| 99久久婷婷国产综合亚洲| 亚洲狠狠婷婷综合久久久久| 奇米影视7777久久精品人人爽| 久久精品视屏| 深夜久久AAAAA级毛片免费看| 久久精品国产精品亚洲艾草网美妙| 7国产欧美日韩综合天堂中文久久久久| 日韩人妻无码一区二区三区久久 | 精品久久久久久久久午夜福利|