eolymp
bolt
Try our new interface for solving problems
Problems

Is it a Tree?

Is it a Tree?

An undirected graph without loops and multiple edges is given by an adjacency matrix. Determine whether this graph is a tree. \InputFile The first line contains the number of vertices $n~(1 \le n \le 100)$ in the graph. Then, an adjacency matrix of size $n \times n$ is given, where $1$ indicates the presence of an edge, and $0$ indicates its absence. The matrix is symmetric with respect to the main diagonal. \OutputFile Print "\textbf{YES}" if the graph is a tree, and "\textbf{NO}" otherwise. \includegraphics{https://static.eolymp.com/content/f6/f62s168ded32f467vq5e71r99o.gif}
Time limit 1 second
Memory limit 128 MiB
Input example #1
3
0 1 0
1 0 1
0 1 0
Output example #1
YES