Mine is playing a game with Tatsumi, where one person sketches some branches and knots and the other determines whether the sketch is of a tree or not. After playing this for a few hours, they've gotten bored and have decided to make the game more abstract. Now, instead of drawing pictures of trees, the couple fills in a 0
or 1
.
Their adjacency matrix stores the relationship between any two knots
An adjacency matrix representing a tree has exactly one path between any pair of
You've decided to join in the fun. Given a
Input Specification
An adjacency matrix, represented by 4 lines, each containing 4 space-separated integers, either 0
or 1
.
Output Specification
Yes
if the given adjacency matrix represents a tree, or No
otherwise.
Tips
If you are unfamiliar with the definition of a tree, this Wikipedia article might help.
Sample Input 1
0 0 0 1
0 0 0 1
0 0 0 1
1 1 1 0
Sample Output 1
Yes
Sample Input 2
0 1 0 1
1 0 0 1
0 0 0 1
1 1 1 0
Sample Output 2
No
Explanation of Output for Sample Input 2
Between Sample 1 and Sample 2, there is a difference of one branch:
Comments
tree:https://en.wikipedia.org/wiki/Tree
read the manga it's less sad
:(