Dynamic Short Path
시간 제한7.5초메모리 제한1024 MB
가중치가 0에서 2인 완전 유향 그래프에서 간선 가중치 갱신이 최대 2000번, min(dist(a,b),2)를 묻는 질의가 최대 100만 번 주어질 때 답을 구한다.
문제
You are given a weighted directed graph with vertices and edges. For any pair of two distinct vertices , there exists an edge with integer weight where .
Process the following queries:
1 a b: Let be the length of the shortest directed path from vertex to vertex (). Output the value .2 a b c: Update to ().
There are at most queries of type 2.
입력
The first line contains two integers and ().
The next lines contain integers. The -th integer of the -th line is (). will be denoted as for all even though no such edge exists.
The next lines contain several integers denoting the queries in the described form.
There is at least 1 query of type 1.
There are at most 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.