Graph
Submit
Language is selected by the extension of the file. See the list of supported languages to know the extension of your language.
Problem
Given an undirected graph of n nodes, find the number of paths of length 'p' from first node to the remaining nodes.
Input:
First line contains two integers p(< n) and n where
p is the length of the path and n is the number of nodes in the graph
Further n lines contain the rows of adjacency matrix of the graph.
The adjacency matrix of a finite graph G on n vertices is the nxn matrix where the non-diagonal entry a[i][j] is the number of edges from vertex i to vertex j and the diagonal entry a[i][i] is 0.
Output:
For each input case, there is one output line consisting of n-1 values with i-th value denoting the number of paths of length p from first node to (i+1)th node.
<br><br>I've removed trailing whitespaces from 2nd output -- shinh<br><br>I've removed trailing whitespaces from 2nd input as well -- shinh
Options
exec is denied
now post-mortem time, all source codes will be revealed
Sample input:_
2 3
0 1 1
1 0 1
1 1 0
2 4
0 1 1 1
1 0 1 1
1 1 0 1
1 1 1 0
Sample output:
1 1
2 2 2
Sample input:_
2 7
0 1 0 0 0 0 1
1 0 1 0 0 0 1
0 1 0 0 0 1 0
0 0 0 0 1 1 0
0 0 0 1 0 1 0
0 0 1 1 1 0 1
1 1 0 0 0 1 0
4 8
0 0 1 1 0 0 1 1
0 0 1 0 0 1 0 0
1 1 0 1 0 0 0 1
1 0 1 0 1 1 1 0
0 0 0 1 0 1 1 1
0 1 0 1 1 0 1 1
1 0 0 1 1 1 0 0
1 0 1 0 1 1 0 0
4 11
0 0 1 1 0 0 1 0 1 0 1
0 0 0 0 0 0 1 0 1 0 1
1 0 0 1 0 1 0 1 0 1 1
1 0 1 0 1 0 0 0 0 0 1
0 0 0 1 0 1 0 0 1 1 1
0 0 1 0 1 0 1 0 1 1 0
1 1 0 0 0 1 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0 0
1 1 0 0 1 1 0 0 0 0 0
0 0 1 0 1 1 0 0 0 0 1
1 1 1 1 1 0 0 0 0 1 0
1 2
0 0
0 0
1 2
0 0
0 0
1 4
0 1 0 0
1 0 1 1
0 1 0 0
0 1 0 0
2 4
0 1 0 0
1 0 1 1
0 1 0 0
0 1 0 0
3 8
0 0 1 1 0 0 1 1
0 0 0 1 0 0 0 0
1 0 0 0 0 1 0 0
1 1 0 0 1 1 0 1
0 0 0 1 0 0 0 1
0 0 1 1 0 0 0 1
1 0 0 0 0 0 0 1
1 0 0 1 1 1 1 0
3 6
0 1 1 1 1 1
1 0 0 1 1 1
1 0 0 0 1 1
1 1 0 0 1 1
1 1 1 1 0 0
1 1 1 1 0 0
1 9
0 1 1 1 1 1 0 1 0
1 0 1 0 1 1 0 1 0
1 1 0 1 1 0 1 0 1
1 0 1 0 0 1 1 0 1
1 1 1 0 0 0 1 0 1
1 1 0 1 0 0 1 1 1
0 0 1 1 1 1 0 1 1
1 1 0 0 0 1 1 0 1
0 0 1 1 1 1 1 1 0
Sample output:
1 1 0 0 1 1
16 36 41 45 49 34 29
42 54 47 60 59 15 15 24 48 54
0
0
1 0 0
0 1 1
1 7 12 3 3 6 11
14 11 14 13 13
1 1 1 1 1 0 1 0
Ranking
Rank | User | Size | Time | Date | Statistics |
---|
1 | yvl | 166 | 0.2468 | 2011/01/26 14:24:31 | 0B / 79B / 75B |
Rank | User | Size | Time | Date | Statistics |
---|
1 | tails | 113 | 0.0018 | 2011/01/25 21:38:55 | 45B / 19B / 38B |
2 | %20(tails) | 111 | 0.0172 | 2015/08/05 19:13:05 | 45B / 19B / 36B |
Rank | User | Size | Time | Date | Statistics |
---|
1 | pooq | 162 | 0.0015 | 2011/01/16 15:20:21 | 0B / 94B / 11B |
Rank | User | Size | Time | Date | Statistics |
---|
1 | nn | 179 | 0.0022 | 2011/02/04 00:14:17 | 0B / 81B / 96B |
2 | nai | 188 | 0.0021 | 2011/01/17 21:23:38 | 0B / 86B / 100B |
3 | not | 192 | 0.0021 | 2011/01/18 01:15:03 | 0B / 90B / 102B |
4 | yuyarin | 193 | 0.0016 | 2011/01/16 10:45:02 | 0B / 90B / 103B |
Rank | User | Size | Time | Date | Statistics |
---|
1 | m.ukai | 190 | 0.0643 | 2011/01/21 18:11:24 | 0B / 110B / 23B |
Rank | User | Size | Time | Date | Statistics |
---|
1 | pooq | 157 | 0.6023 | 2011/01/28 16:08:14 | 0B / 91B / 12B |
Language Ranking_
Rank | Lang | User | Size | Score |
1 | J | I., S.(thx4smpltreatmnt>shinh) | 58 | 10000 |
2 | Perl | %20(tails) | 111 | 5225 |
3 | Python | hallvabo (embed) | 127 | 4566 |
4 | AWK | I., S. | 153 | 3790 |
5 | R | pooq | 157 | 3694 |
6 | BASIC | pooq | 162 | 3580 |
7 | Ruby | yvl | 166 | 3493 |
8 | JavaScript | nn | 178 | 3258 |
9 | C | nn | 179 | 3240 |
10 | OCaml | m.ukai | 190 | 3052 |
return to the top page