#P10048. [CCPC 2023 北京市赛] 图

[CCPC 2023 北京市赛] 图

Problem Description

Given an undirected complete graph with nn vertices and positive edge weights, 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 (a,b)(a,b).

Input Format

The first line contains a positive integer n (1n500)n \ (1 \le n \le 500), representing the number of vertices in the graph.

The next nn lines each contain nn numbers, forming an n×nn \times n matrix. The number ai,j (1ai,j106)a_{i,j} \ (1 \leq a_{i,j} \leq 10^6) in row ii and column jj represents the length of the edge between (i,j)(i,j). In particular, ai,i=0a_{i,i} = 0.

It is guaranteed that ai,j=aj,ia_{i,j} = a_{j,i}.

Output Format

Output a 0101 matrix of size nn. The value in row ii and column jj is 11 if the edge (i,j)(i,j) satisfies the requirement stated in the problem, and 00 otherwise.

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

4
0 3 2 100
3 0 8 100
2 8 0 10
100 100 10 0
0110
1000
1001
0010

Hint

Translated by ChatGPT 5