0% found this document useful (0 votes)
22 views

Input: Y Is Not Reachable From The Start Node Then Node Y Does Not

This document describes how to find dominator relationships between nodes in a directed graph. A node X dominates node Y if every path from the start node to Y goes through X. The input specifies the number of test cases and the edges in each graph. For each case, the output should display the dominator relationships between all pairs of nodes in a table, with Y if node A dominates node B, and N otherwise.

Uploaded by

totalblood
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Input: Y Is Not Reachable From The Start Node Then Node Y Does Not

This document describes how to find dominator relationships between nodes in a directed graph. A node X dominates node Y if every path from the start node to Y goes through X. The input specifies the number of test cases and the edges in each graph. For each case, the output should display the dominator relationships between all pairs of nodes in a table, with Y if node A dominates node B, and N otherwise.

Uploaded by

totalblood
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

In graph theory, a node X dominates a node Y if every path

from the predefined start node to Y must go through X. If


Y is not reachable from the start node then node Y does not
have any dominator. By definition, every node reachable from
the start node dominates itself. In this problem, you will be
given a directed graph and you have to find the dominators
of every node where the 0-th node is the start node.
As an example, for the graph shown right, 3 dominates 4
since all the paths from 0 to 4 must pass through 3. 1 doesn’t
dominate 3 since there is a path 0-2-3 that doesn’t include 1.

Input
The first line of input will contain T (≤ 100) denoting the
number of cases.
Each case starts with an integer N (0 < N < 100) that
represents the number of nodes in the graph. The next N lines contain N integers each. If the j-th (0
based) integer of i-th (0 based) line is ‘1’, it means that there is an edge from node i to node j and
similarly a ‘0’ means there is no edge.

Output
For each case, output the case number first. Then output 2N + 1 lines that summarizes the dominator
relationship between every pair of nodes. If node A dominates node B, output ‘Y’ in cell (A, B),
otherwise output ‘N’. Cell (A, B) means cell at A-th row and B-th column. Surround the output with
‘|’, ‘+’ and ‘-’ to make it more legible. Look at the samples for exact format.

Sample Input
2
5
0 1 1 0 0
0 0 0 1 0
0 0 0 1 0
0 0 0 0 1
0 0 0 0 0
1
1

Sample Output
Case 1:
+---------+
|Y|Y|Y|Y|Y|
+---------+
|N|Y|N|N|N|
+---------+
|N|N|Y|N|N|
+---------+
|N|N|N|Y|Y|
+---------+
|N|N|N|N|Y|
+---------+
Case 2:
+-+
|Y|
+-+

You might also like