How do we solve this problem in Java language? Thank you! We can describe the physical structure of some designs using an undirected graph. We’ll say vertex i is part of a triangle if i has two different neighbors j and k such that j and k are neighbors of each other. For this problem, find weak vertices in graphs – those vertices that is not part of any triangle. Figure 1: An illustration of the weak vertices (which are shaded) from the sample input graph. Input Input consists of up to 100 graphs. Each starts with an integer, 1 ≤ n ≤ 20, giving the number of vertices in the graph. Next come n lines with n integers on each line, which describe an n×n adjacency matrix for the graph. Vertices are numbered from 0 to n−1. If the adjacency matrix contains a one at row r, column c (where 0 ≤ r, c ≤ n−1), it means that there is an edge from vertex r to vertex c. Since the graph is undirected, the adjacency matrix is symmetric. The end of input is marked by a value of −1 for n. Output For each graph, produce a line listing the weak vertices ordered from least to greatest.
How do we solve this problem in Java language? Thank you!
We can describe the physical structure of some designs using an undirected graph. We’ll say vertex i is part of a triangle if i has two different neighbors j and k such that j and k are neighbors of each other. For this problem, find weak vertices in graphs – those vertices that is not part of any triangle.
Input
Input consists of up to 100 graphs. Each starts with an integer, 1 ≤ n ≤ 20, giving the number of vertices in the graph. Next come n lines with n integers on each line, which describe an n×n adjacency matrix for the graph. Vertices are numbered from 0 to n−1. If the adjacency matrix contains a one at row r, column c (where 0 ≤ r, c ≤ n−1), it means that there is an edge from vertex r to vertex c. Since the graph is undirected, the adjacency matrix is symmetric. The end of input is marked by a value of −1 for n.
Output
For each graph, produce a line listing the weak vertices ordered from least to greatest.
![Sample Input 1
Sample Output 1
9.
1 8
0 1
1
1 0 0 0 0 0
1 0 0 0 0 0 1 0 0
1 0 0 1 0 1 0 0 0
1 0 10 0 1 1 0 0
0 0 0 0 0 0 1 1 0
0 0 1 1 0 0 0 0 0
0 1 0 1 1 0 0 1 0
0 0 0 0
1 0 10 1
0 0 0 0 0 0 0 1 0
1
-1](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F138bcebf-db0b-42f0-bb5c-dfa12c40df11%2F01eeb63f-93e8-4e46-8924-b069f39d68a5%2Fa5xfa3z_processed.png&w=3840&q=75)
![Figure 1: An illustration of the weak vertices (which are shaded) from the sample input graph.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F138bcebf-db0b-42f0-bb5c-dfa12c40df11%2F01eeb63f-93e8-4e46-8924-b069f39d68a5%2F0orrl7m_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)