1+ """
2+ 1. bfs
3+ - queue
4+ - 인접 node
5+ (x,y) = [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]
6+ 2. sorting
7+ 낮은 번호부터
8+ """
9+ from collections import deque
10+ n , k = map (int , input ().split ())
11+ graph = [[] for _ in range (n )]
12+ for i in range (n ):
13+ graph [i ]= list (map (int ,input ().split ()))
14+ s ,x ,y = map (int , input ().split ())
15+ print (graph )
16+ # 1.번호 순대로 초기 바이러스 정보 정렬
17+ virus_info = []
18+ for i in range (n ):
19+ for j in range (n ):
20+ if graph [i ][j ] != 0 :
21+ virus_info .append ([graph [i ][j ],0 ,[i ,j ]]) # [번호,시간,위치]
22+ #2.dfs
23+ # virus_info == queue
24+ virus_info .sort ()
25+ print (virus_info )
26+ t = 0
27+ while t < s :
28+ virus_info .sort ()
29+ for node in virus_info :
30+ print ("t" ,t ,"=" ,virus_info )
31+ queue = deque ([node ])
32+ now = queue .popleft ()
33+ num , t , position = now
34+ near_nodes = [[position [0 ],position [1 ]+ 1 ],
35+ [position [0 ],position [1 ]- 1 ],
36+ [position [0 ]- 1 ,position [1 ]],
37+ [position [0 ]+ 1 ,position [1 ]]
38+ ] # 상하좌우
39+
40+ t += 1
41+ if t > s :
42+ break
43+ for v in near_nodes : # v = [x,y]
44+ if n > v [0 ] and v [0 ]>= 0 and n > v [1 ] and v [1 ]>= 0 :
45+ if graph [v [0 ]][v [1 ]] == 0 :
46+ virus_info .append ([num ,t ,v ]) # 번호, 시간, 위치
47+ graph [v [0 ]][v [1 ]] = num
48+ print (f"graph node = { node } , => { graph } " )
49+ # print(f"graph {v[0]},{v[1]}:{graph[v[0]][v[1]]}")
50+ # print(f"num, t, position {num} , {t} , {position}")
51+
52+ # print("#",virus_info)
53+ # print("##",graph)
54+ # print("###", graph[x][y])
55+ print (graph [x - 1 ][y - 1 ])
0 commit comments