Company: Teradata

Difficulty: medium

Problem Statement

Shortest Distance with a Zero-Cost Special Node You are given an undirected graph with N nodes numbered from 0 to N-1 and M edges. Each edge is given as a pair [u, v] and every edge costs 1 to traverse. You are also given a source node S and a special node V . Travelling normally costs 1 per edge. However, the moment a walk stands on the special node V , every edge traversed afterwards is free: from that point on the cost of the walk never grows, no matter how many more edges are used. For every node i , report the minimum possible cost of a walk that starts at S and ends at i under this rule. If no walk from S can reach node i at all, report -1 for that node. The graph may contain self-loops and repeated edges, and it is not necessarily connected. Input Format The first line contains two integers N and M . Each of the next M lines contains two integers u and v , describing an undirected edge between u and v . The last line contains two integers S and V : the source node and the specia

More Teradata OA questionsInterview experiences