아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Dynamic Short Path

시간 제한7.5초메모리 제한1024 MB

요약
가중치가 0에서 2인 완전 유향 그래프에서 간선 가중치 갱신이 최대 2000번, min(dist(a,b),2)를 묻는 질의가 최대 100만 번 주어질 때 답을 구한다.
난이도

보통10점 중 7점

유형
그래프, 최단 경로, 동적 계획법
정답자
아직 제출이 없습니다

문제

You are given a weighted directed graph with nn vertices and n(n−1)n(n-1) edges. For any pair of two distinct vertices 1≤i,j≤n1 \le i, j \le n, there exists an edge with integer weight w(i,j)w(i, j) where 0≤w(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 (1≤a,b≤n1 \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 (1≤a,b≤n,0≤c≤2,a≠b1 \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 (2≤n≤600,1≤q≤1062 \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) (0≤w(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.

예제1

  1. 예제 1

    입력
    5 10
    0 1 2 2 2
    2 0 2 2 2
    2 2 0 1 2
    2 2 2 0 2
    2 2 2 2 0
    1 1 2
    1 2 1
    1 1 3
    1 1 4
    1 4 5
    1 5 5
    2 4 5 0
    1 4 5
    1 2 5
    1 1 5
    
    예상 출력
    1
    2
    2
    2
    2
    0
    0
    2
    2