We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Find the nearest clone
- Discussions
Find the nearest clone
Find the nearest clone
Sort by
recency
|
189 Discussions
|
Please Login in order to post a comment
What the **** is the need for the variable val?
Python
javascript
Test Case 12 has no answer and is the wrong expected output. There is no edge linking the nodes with colour 2 in the graph.
!/bin/python3
import math import os import random import re import sys from collections import defaultdict
This class represents a directed graph
using adjacency list representation
class Graph:
Complete the findShortest function below.
#
For the weighted graph, :
#
1. The number of nodes is _nodes.
2. The number of edges is _edges.
3. An edge exists between _from[i] to _to[i].
# # def findShortest(graph_nodes, graph_from, graph_to, ids, val): # solve here n= graph_nodes g = Graph() for i in range(len(graph_from)): g.addEdge(graph_from[i],graph_to[i]) g.addEdge(graph_to[i],graph_from[i]) if ids.count(val)<=1: return -1 dico = g.BFS(val) for i in range(1,n+1): if i not in dico.keys(): dico[i]=g.BFS(i)[i] s=[] for k in range(len(ids)): if ids[k]==2 and dico[k+1]>0: s.append(dico[k+1]) print(s)
if name == 'main': fptr = open(os.environ['OUTPUT_PATH'], 'w')