Junctions

시간 제한2초메모리 제한2048 MB

요약
완전 가중 그래프가 인접 행렬로 주어질 때, 어떤 두 정점 사이의 모든 최단 경로가 반드시 지나는 간선 (i,j)를 찾아 표시한다.
난이도

어려움10점 중 8점

유형
그래프, 최단 경로, 행렬
정답자
아직 제출이 없습니다

문제

The streets and junctions of the Martian City can be represented as a weighted bidirectional complete graph where the nn junctions are the vertices and the streets are the edges. The weight of an edge is the length of the corresponding street.

For each edge (a,b)(a, b), determine whether there exists a pair of vertices (x,y)(x, y) such that all shortest paths from xx to yy pass through the edge (a,b)(a, b).

입력

The first line contains a positive integer nn (1≤n≤5001 \le n \le 500) representing the number of junctions in the city.

Each of the next nn lines contains nn space-separated integers. Together, they form an n×nn \times n matrix. The number a_i,ja\_{i, j} (1≤a_i,j≤1061 \leq a\_{i, j} \leq 10^6) in the ii-th row and jj-th column represents the length of the bidirectional street between junctions ii and jj. Specifically, a_i,i=0a\_{i, i} = 0 and a_i,j=a_j,ia\_{i, j} = a\_{j, i}.

출력

Output a binary matrix of size n×nn \times n without spaces. The entry in the ii-th row and jj-th column must be 11 if the edge (i,j)(i, j) satisfies the conditions described in the problem, and 00 otherwise.

In particular, output 00 when i=ji = j.

예제1

  1. 예제 1

    입력
    4
    0 3 2 100
    3 0 8 100
    2 8 0 10
    100 100 10 0
    
    예상 출력
    0110
    1000
    1001
    0010