Vertices and edges

2.9

12 votes
DAG, Shortest Path Algorithm, Topological sorting, Graphs, Algorithms, Shortest Path Algorithms
Problem

You are given an undirected weighted graph with n vertices and m edges.

Consider all shortest paths between vertices 1 and n, for any vertex such as v (1vn), say that, if v is in either all shortest paths or some of them or none of them.

Input format

  • The first line contains two integers n,m denoting the number of the graph's vertices and edges respectively.
  • Each of the following m lines contains space-separated vi,ui, and wi describing the graph's ith edge's vertices (vi,ui) and its weight (wi).

Output format

Print n lines where the ith line contains either all if vertex i is in all shortest paths between 1 to n or some if vertex i is in some of shortest paths or none otherwise.

Constraints

1n2×1051m3×105

1vi,uin1wi109

It is guaranteed that there are no multiple edges or self-loops in the graph.
Also, it is guaranteed that the graph is connected.

Time Limit: 1.5
Memory Limit: 256
Source Limit:
Explanation

The only shortest path is 1,5,6, so they are in all shortest paths and others are in no shortest paths.

Editor Image

?