-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdfs.ini
41 lines (36 loc) · 1008 Bytes
/
dfs.ini
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import numpy as np
N=int(input())
A=np.zeros((N+1,N+1))
graph = [[] for _ in range((N+1)*(N+1))]
for i in range(1,N+1):
a=input()
aa=[int(x) for x in list(str(a))]
# print(a)
for j in range(1,N+1):
# print(i,j)
A[i][j]=a[j-1]
if i-1 > 0:
graph[(i-1)*(N)+j].append((i-2)*(N)+j)
if i+1 < N+1:
graph[(i-1)*(N)+j].append((i)*(N)+j)
if j-1 > 0:
graph[(i-1)*(N)+j].append((i-1)*(N)+j-1)
if j+1 < N+1:
graph[(i-1)*(N)+j].append((i-1)*(N)+j+1)
print(A)
print(graph)
#########入力##########
4
1161
1119
7111
1811
##########出力#########
[[0. 0. 0. 0. 0.]
[0. 1. 1. 6. 1.]
[0. 1. 1. 1. 9.]
[0. 7. 1. 1. 1.]
[0. 1. 8. 1. 1.]]
[[], [5, 2], [6, 1, 3], [7, 2, 4], [8, 3], [1, 9, 6], [2, 10, 5, 7], [3, 11, 6, 8], [4, 12, 7], [5, 13, 10], [6, 14, 9, 11], [7, 15, 10, 12], [8, 16, 11], [9, 14], [10, 13, 15], [11, 14, 16], [12, 15], [], [], [], [], [], [], [], []]
[[2, 4]]
#####################