Competitive Programming with Python | Topological Sort

preview_player
Показать описание
Title: Topological Sort
Description: Topological Sort via Source Removal Algorithm

#CompetitiveProgramming #ProgrammingKnowledge #Topological #TopologicalSort #DijkstrasAlgorithm #NumberTheory #Python #Sieve #BitMagic
★★★Top Online Courses From ProgrammingKnowledge ★★★

★★★ Online Courses to learn ★★★

★★★ Follow ★★★

DISCLAIMER: This video and description contains affiliate links, which means that if you click on one of the product links, I’ll receive a small commission. This help support the channel and allows us to continue to make videos like this. Thank you for the support!
Рекомендации по теме
Комментарии
Автор

if you dont want to convert it to integer then you can do in this way:

from collections import defaultdict

def topological(graph):
degree = defaultdict(int)
for node in graph:
for adjnode in graph[node]:
degree[adjnode] += 1
bfs = [i for i in graph if degree[i] == 0]
for node in bfs:
for adjnode in graph[node]:
degree[adjnode] -= 1
if(degree[adjnode] == 0):
bfs.append(adjnode)
return bfs



vrt, e = map(int, input().split())
graph = defaultdict(list)
for i in range(e):
u, v = map(str, input().split())
graph[u].append(v)
a= topological(graph )
print(a)

PrashantPathakbcs
Автор

Sir, I want to know how far will you take this playlist, which topics we will cover.

shivammalviya
Автор

can u make videos more frequently? have been waiting for a week for this video. hope the next videos wont take that much time

josewinjeyabalan