#P10265. [GESP样题 七级] 迷宫统计
[GESP样题 七级] 迷宫统计
Background
Related multiple-choice and true/false problems: https://ti.luogu.com.cn/problemset/1107.
Problem Description
On a mysterious fantasy continent, there are ancient and magical mazes, numbered from to . Between some mazes, you can travel directly both ways; between some others, you can travel from one maze to another, but cannot come back. The player Xiao Yang wants to challenge different mazes, and he decides to start from maze . Now he needs your help to count: how many mazes can directly reach maze , how many other mazes maze can directly reach, and output the sum of these two numbers.
Note that for maze (), it can always directly reach itself.
Input Format
The first line contains two integers and , representing the total number of maze nodes and the index of the specified starting maze.
The next lines each contain integers, describing the relations between mazes. For the integer in row , column , means you can directly go from maze to maze , and means you cannot directly go.
Output Format
Output one line with three integers separated by spaces: the number of other mazes that maze can directly reach, the number of mazes that can directly reach maze , and the sum of these two counts.
6 4
1 1 0 1 0 0
0 1 1 0 0 0
1 0 1 0 0 1
0 0 1 1 0 1
0 0 0 1 1 0
1 0 0 0 1 1
3 3 6
Hint
Explanation of Sample 1
Maze can directly reach mazes , for a total of .
Mazes that can directly reach maze are , for a total of .
In total, there are .
Constraints
| Subtask | Score | |
|---|---|---|
For all testdata, it is guaranteed that .
Translated by ChatGPT 5