Logo
(追記) (追記ここまで)

23171번 - Dynamic Short Path 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
7.5 초 (추가 시간 없음) 1024 MB179321717.347%

문제

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

Process the following $q$ queries:

  • 1 a b: Let $dist(a, b)$ be the length of the shortest directed path from vertex $a$ to vertex $b$ (1ドル \le a, b \le n$). Output the value $\min(dist(a, b), 2)$.
  • 2 a b c: Update $w(a, b)$ to $c$ (1ドル \le a, b \le n, 0 \le c \le 2, a \neq b$).

There are at most 2ドル,000円$ queries of type 2.

입력

The first line contains two integers $n$ and $q$ (2ドル \le n \le 600, 1 \le q \le 10^6$).

The next $n$ lines contain $n$ integers. The $j$-th integer of the $i$-th line is $w(i, j)$ (0ドル \le w(i, j) \le 2$). $w(i, i)$ will be denoted as 0ドル$ for all $i$ even though no such edge exists.

The next $q$ 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ドル,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

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

1
2
2
2
2
0
0
2
2

힌트

출처

University > KAIST > KAIST ICPC Mock Competition > 2021 KAIST 11th ICPC Mock Competition B번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /