其他分享
首页 > 其他分享> > No.18 Is It a Tree

No.18 Is It a Tree

作者:互联网

原文:

Is It a Tree 

1000ms 65536kB

描述:

Given edges of a graph with N nodes. Check whether it is a tree.

输入:

First line: one positive integers N (N <= 100).
Next N lines: an N*N 0/1 matrix A={a[i][j]}, indicating whether there exists an edge between node i and node j (a[i][j]=1) or not (a[i][j]=0).

输出:

One integer, 1 if the graph is a tree, or 0 otherwise.

样例输入:

4
0 1 0 1
1 0 1 0
0 1 0 0
1 0 0 0

样例输出:

1

参考译文:

这是一棵树吗?

描述:

给出一张图上的n个节点,判断这张图是否为一棵树。

输入:

第一行包含一个整数N

接下来N行,用于表示一个N*N的矩阵,用0表示该处没有节点,用1表示该处有节点

输出:

一个整数,1表示该图是一棵树,否则输出0。

样例输入:

4
0 1 0 1
1 0 1 0
0 1 0 0
1 0 0 0

样例输出:

1

标签:输出,Tree,No.18,样例,一棵树,graph,节点,输入
来源: https://blog.csdn.net/Chen_q_/article/details/123027682