Dynamic Short Path

아직 제출이 없습니다시간 제한7.5초메모리 제한1024 MB

문제

You are given a weighted directed graph with nn vertices and n(n1)n(n-1) edges. For any pair of two distinct vertices 1i,jn1 \le i, j \le n, there exists an edge with integer weight w(i,j)w(i, j) where 0w(i,j)20 \le w(i, j) \le 2.

Process the following qq queries:

  • 1 a b: Let dist(a,b)dist(a, b) be the length of the shortest directed path from vertex aa to vertex bb (1a,bn1 \le a, b \le n). Output the value min(dist(a,b),2)\min(dist(a, b), 2).
  • 2 a b c: Update w(a,b)w(a, b) to cc (1a,bn,0c2,ab1 \le a, b \le n, 0 \le c \le 2, a \neq b).

There are at most 2,0002\\,000 queries of type 2.

입력

The first line contains two integers nn and qq (2n600,1q1062 \le n \le 600, 1 \le q \le 10^6).

The next nn lines contain nn integers. The jj-th integer of the ii-th line is w(i,j)w(i, j) (0w(i,j)20 \le w(i, j) \le 2). w(i,i)w(i, i) will be denoted as 00 for all ii even though no such edge exists.

The next qq lines contain several integers denoting the queries in the described form.

There is at least 1 query of type 1.

There are at most 2,0002\\,000 queries of type 2.

출력

For each query of type 1, output a single integer denoting the answer to that query. Each answer should go on its own line.