Is It A Tree?(待做)

題目描述

A tree is a well-known data structure that is either empty (null, void, nothing) or is a set of one or more nodes connected by directed edges between nodes satisfying the following properties. There is exactly one node, called the root, to which no directed edges point. Every node except the root has exactly one edge pointing to it. There is a unique sequence of directed edges from the root to each node. For example, consider the illustrations below, in which nodes are represented by circles and edges are represented by lines with arrowheads. The first two of these are trees, but the last is not.

In this problem you will be given several descriptions of collections of nodes connected by directed edges. For each of these you are to determine if the collection satisfies the definition of a tree or not.

輸入描述:

The input will consist of a sequence of descriptions (test cases) followed by a pair of negative integers. Each test case will consist of a sequence of edge descriptions followed by a pair of zeroes Each edge description will consist of a pair of integers; the first integer identifies the node from which the edge begins, and the second integer identifies the node to which the edge is directed. Node numbers will always be greater than zero and less than 10000.

輸出描述:

For each test case display the line "Case k is a tree." or the line "Case k is not a tree.", where k corresponds to the test case number (they are sequentially numbered starting with 1).

示例1

輸入

6 8  5 3  5 2  6 4
5 6  0 0

8 1  7 3  6 2  8 9  7 5
7 4  7 8  7 6  0 0

3 8  6 8  6 4
5 3  5 6  5 2  0 0
-1 -1

輸出

Case 1 is a tree.
Case 2 is a tree.
Case 3 is not a tree.
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末庶溶,一起剝皮案震驚了整個(gè)濱河市煮纵,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌偏螺,老刑警劉巖行疏,帶你破解...
    沈念sama閱讀 211,265評論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異套像,居然都是意外死亡酿联,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,078評論 2 385
  • 文/潘曉璐 我一進(jìn)店門夺巩,熙熙樓的掌柜王于貴愁眉苦臉地迎上來贞让,“玉大人,你說我怎么就攤上這事柳譬≡牛” “怎么了?”我有些...
    開封第一講書人閱讀 156,852評論 0 347
  • 文/不壞的土叔 我叫張陵美澳,是天一觀的道長销部。 經(jīng)常有香客問我摸航,道長,這世上最難降的妖魔是什么舅桩? 我笑而不...
    開封第一講書人閱讀 56,408評論 1 283
  • 正文 為了忘掉前任酱虎,我火速辦了婚禮,結(jié)果婚禮上擂涛,老公的妹妹穿的比我還像新娘读串。我一直安慰自己,他們只是感情好歼指,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,445評論 5 384
  • 文/花漫 我一把揭開白布爹土。 她就那樣靜靜地躺著,像睡著了一般踩身。 火紅的嫁衣襯著肌膚如雪胀茵。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,772評論 1 290
  • 那天挟阻,我揣著相機(jī)與錄音琼娘,去河邊找鬼。 笑死附鸽,一個(gè)胖子當(dāng)著我的面吹牛脱拼,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播坷备,決...
    沈念sama閱讀 38,921評論 3 406
  • 文/蒼蘭香墨 我猛地睜開眼熄浓,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了省撑?” 一聲冷哼從身側(cè)響起赌蔑,我...
    開封第一講書人閱讀 37,688評論 0 266
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎竟秫,沒想到半個(gè)月后娃惯,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,130評論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡肥败,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,467評論 2 325
  • 正文 我和宋清朗相戀三年趾浅,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片馒稍。...
    茶點(diǎn)故事閱讀 38,617評論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡皿哨,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出纽谒,到底是詐尸還是另有隱情往史,我是刑警寧澤,帶...
    沈念sama閱讀 34,276評論 4 329
  • 正文 年R本政府宣布佛舱,位于F島的核電站椎例,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏请祖。R本人自食惡果不足惜订歪,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,882評論 3 312
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望肆捕。 院中可真熱鬧刷晋,春花似錦、人聲如沸慎陵。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,740評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽席纽。三九已至捏悬,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間润梯,已是汗流浹背过牙。 一陣腳步聲響...
    開封第一講書人閱讀 31,967評論 1 265
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留纺铭,地道東北人寇钉。 一個(gè)月前我還...
    沈念sama閱讀 46,315評論 2 360
  • 正文 我出身青樓,卻偏偏與公主長得像舶赔,于是被迫代替她去往敵國和親扫倡。 傳聞我的和親對象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,486評論 2 348

推薦閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,308評論 0 10
  • 今天第11天竟纳,剛好看到一篇日耕到11天要放棄的撵溃。 雖然我這10天也是絞盡腦汁,還在湊字?jǐn)?shù)的階段蚁袭,但是沒有一開始那么...
    一年后的自己2019年1月28閱讀 112評論 0 0
  • 每日踐行正面管教 大家好征懈,我是正面管教家長講師Ivy Ding,我陪大家一起踐行正面管教揩悄。我第30天打卡卖哎,相信大家...
    小妖丁兒閱讀 388評論 0 0
  • 今天又來和大家分享心得了。之前在教育孩子的問題上我分享過相信的力量删性,榜樣的力量亏娜,今天我想要和大家分享一下贊美的力量...
    學(xué)慧愛閱讀 410評論 1 1
  • "你他媽給我滾出去"聽到這句話有人馬上瞪紅了眼,有人會拿起身邊的異物朝對方扔了過去蹬挺,當(dāng)然也有人真的滾了出去...
    亦凡_閱讀 225評論 0 2