This video demonstrates advanced graph algorithm optimization techniques, including state dominance pruning (where state A dominates state B if everything reachable from B is also reachable from A), binary search on answer for finding minimum maximum edge weights, and multi-source BFS for pathfinding problems. The speaker emphasizes that understanding the problem structure is crucial for selecting the right algorithm, whether BFS, Dijkstra, or specialized approaches like Union-Find for minimum effort path problems.
Deep Dive
Voraussetzung
- Keine Daten verfügbar.
Nächste Schritte
- Keine Daten verfügbar.
Deep Dive
Leetcode hards / codeforces / graphsHinzugefügt:
[clears throat and cough] [clears throat] Okay, now I'm live. [clears throat] more graph problems.
Um, how do I link how do I get a link to this here?
One sec.
It's 7:07 p.m. No, it's midnight.
Why don't I sleep? Yeah, I want to finish a few more questions.
Is it 7:07 p.m. anywhere?
Okay, this is what I was looking at earlier.
We um we have to move cursor below to close this.
Do you work as a sweet? No, I just left my job.
How much do I grind? I've been uh doing a lot recently, but I might join a a company soon. Did I do the problems today? Yeah, I did.
I'm flying to meet with the company tomorrow because they're making a very compelling offer and they seem to have a lot of talent.
So, I'm going to see what's up with that.
All right. So, I'm sorry I can't explain any problems right now. I want to finish the things I'm working on.
>> [clears throat] >> We have 20 by 20 classroom.
Well, like I wouldn't when you first started doing le code, did you go back and redo problems you couldn't solve? I mean, I can't redo a problem that I can't solve because then I never did it in the first place. I'm not sure exactly what you mean.
What will be with Hello. What's up?
Have I seen you on LinkedIn? I have.
I've seen you.
Where do I live? I live in New York. I don't don't get the answer. Well, if I look at the solution, I'm going to I'm going to learn it right then and there.
I'm not going to just like read it, and then kind of move on. I'm going to spend a long time understanding it, looking at every way to solve it, trying different implementations, learning all of that.
Yeah, you always get uh four out of four on your contests, which is awesome. So, what am I doing here? This is like am I crazy for putting this at four, maybe five, because we need this small pruning optimization, which I think is a little bit clever.
Um, and I don't know if we needed it in C++.
I'm going to ask Claude because I want to test something.
I had to use a code just without the I want to test if it passes in C++ without any printing.
So I'm having claw generate code for me so I can paste it in and see.
Um, okay. Let's see.
Cuz did I get teles the first time?
Yeah, the first time I did it in contest, I got teles in Python with no pruning.
Oh, and it doesn't work in C++ either without the printing. Interesting.
So, I had pruned highest energy at a state, right? Because I would never visit a state with worse energy.
I would also never visit a state with the same position and the same energy and like a worse amount of litter picked up. So I think there's multiple pruning we can do.
So if I put the best energy it actually reduces does it not reduce the complexity?
Maybe not just energy.
So instead of seeing right I want to do like highest energies.
I don't need scene at all.
What was energy I?
Where is this variable even? Oh, maybe energy input and then I need to remove.
So, what is it doing here?
Get the RC, right? Energy is still going to be in the state.
If we had better energy, skip it. Set it. But I should probably set on push, not on pop.
Um, this is like a bit odd to think about.
I guess here is fine for now energy something like this right what's wrong with I want to see if the runtime changes.
I don't have to initialize this.
Did that change 3.2? It only moved a little bit.
What is the optimization here?
Well, I live in 2015. What does that mean? Multiple people have said that.
Is there a a better asmtoic solution?
This one seems to have skipped energy.
How does that work?
Okay, this is actually wrong. The complexity.
How do you earn money? Um, I mean, I'm fortunate enough I don't need to make money right now.
What's my future plan? I don't know.
Just going to do coding problems for now.
I'm visiting I'm flying to California tomorrow because I'm meeting a company that is making a very compelling offer.
But we'll see.
I'm not in a rush to return to work.
And the company is called Etched Etched AI.
Is there any way Is there any way to optimize the asmtoics of this? [snorts] Right. We want to minimize the walking distance.
We can use a normal BFS. We don't have to use dystra or 01 bfs. Why did some people use dystra?
How about this?
Unrefer to Python users with four states. BFS doesn't work.
They only have three states in their dice stra.
Can I do leak code weekly 425?
The last problem.
Um, that looks like a somewhat annoying DP problem on trees.
I'm not going to do it right now, but my code is online for it, I think.
Okay. So, what other forms of pruning are there besides my highest energy per state tracking?
We also do best little mouse The general framework is dominance.
State A dominates state B if anything reachable from B is reachable from A.
That makes sense. Energy dominance works.
Litter mask dominance only works on like sub masks. So that's somewhat annoying.
move count dominance is implicit in the BFS.
All right. Well, I think that this is instead we can print it in the So, I'm in the dy I'm in the BFS and I'm processing one later at a time.
track.
Don't think we can improve the asmtoics with anything else. This is a really nice problem.
I should probably reimplement with pruning.
Try different push proping ideas.
Grab this.
Put it in Get home with the 568 to get link.
It's like a matrix BFS but pretty tricky. Maybe a six.
Yeah, this is fine.
Oh, wait. And um we need to add bit operations as a tag.
It's like kind of easy application of fit.
All right, got this one.
just um around 2,000 more questions I have to categorize, then I'll finally be done.
I'm trying to do 30 a day or so.
That's another couple months.
Okay.
Can't wait to be done with that. There's a ball in a maze.
We can roll until we hit a wall.
Return the path that we actually need to follow to go into the hole with the shortest distance.
So, we have weighted edges.
Would this work?
Left, up, left. Yeah, we have weighted edges. So, we can premp compute every weighted edge, right? There's just four * n * m weighted edges. Then we run dystra with um with like path reconstruction.
How did I do the path reconstruction here?
Where even is it?
Wait, what the hell? I put the path in the heap.
Why did I do that?
That doesn't seem right. We don't need to do that, right?
What was I doing? When did I when did I write this code?
Oh, wait. The the [clears throat] path needs to be the lexographically smallest path.
Huh.
If it's lexic, if we care about the lexica graph, like there's a reason that we're going left up left here instead of up left because that is a a smaller lexica graphical string. So is there a way to do it without putting the path inside the heap?
They put it in the heap here.
What the hell was this? Um, did everybody do it? How did Alex voice do it? Cuz he's quite strong.
He also put it in the heap.
Did I do any sort of pruning here?
I didn't. What is the asmtoics if we just put the path in the heap directly?
The asmtotics don't seem great here. I'm also not even pruning.
What is this?
Key. I kind of want to redo this.
I mean, just the dextrous part.
I should try it, I guess.
My profile on lead code.
This is my profile.
This URL leadgoat.io. I think it should be in the description of the screen of the stream.
All right, I'm just going to redo this because I'm curious about a few things.
So, let's make it hold this path RC.
Oh, 2500. Yeah, I fell a bunch. But my last two contests were really good. So, I'm going to go back up to 2600 cuz I got uh top 50 in one and top 100 in the other.
But yeah, it's the lowest I've been in a while. I'm getting worse.
So uh min d equals sure the skin can map this. Wait, we really just need a map of R to RC to minist, right? I'm so far I'm writing exactly what I wrote like two years ago, but that's fine.
We already reached here at a faster pace. We skip it.
Um I guess we have this case.
Where's our target?
something like this.
Um, how would I get my edge cost before something with the DP?
I made nice helper functions last time.
push.
What was the state? Uh, n cost end path n something like this if I have to skip if Sorry.
Step out of bounds.
What is this?
I like the way I've written it here because I have some actual printing, but I'm going to just check what's wrong.
Okay, thank you. Claude said um this is wrong. Why do I even have NR and NC?
I don't need any of this.
Something like this, right?
And now that should be faster. No, it's the same speed as what I wrote.
All right, whatever. I like this implementation more.
Um, it's going to roll me.
You want to move it into the goal.
How do you be consistent? Uh, you just do it. Like you got to want it badly enough. Whatever it is you're going after in life, right?
You know, I never really understood that question to be honest. If you want something, go do it.
Um so we store the path directly in the heap shows.
Now if we pop we always get best disc.
If I tie on this, we get best.
Let's still print by distance as normal.
This is a interesting question.
I'd like to reimplement this at some point eventually.
Add this to my set.
PT. What is PT file type?
Get the GitHub link for that.
The maze three.
This is like quite an odd usage of dyra.
Give it a four. And it's kind of like DP reconstruction, but it's really weird.
Let's um make sure these are updated in the dextro group.
BFS group.
All right.
What's next?
Oh, yeah. And that problem technically uses DP to premp compute next edges, but it's kind of It's like a secondary.
Not really the main point of the question.
Minimize the maximum edge weight of a graph.
So we have a a directed weighted graph all big constraints.
Um we have to move some edges such that everything can still hit node zero.
And we want to make the edges generally small.
Minimum possible value is such a weird question, but it sounds like a binary search, right?
So let's say can every edge be under infinity?
To do that I have to first remove let's say like a thousand can every edge be under a thousand we first remove every every edge above a th00and and then out of these outgoing edges what can threshold be I need to remove even more potential eventually and zero still needs to be reachable.
Zero being reachable from all nodes really means I need to reach every node from zero. So I can probably reverse that graph.
Um how do I handle this second condition?
removing the two to zero step.
Oh, wait. We don't need to actually check that condition.
It's like we we remove every edge above a certain weight and then I just need to check can I reach every node from can't reach every node from node zero.
There's some sort of articulation point thing or something.
Yeah, I also evidently did this problem in a contest like probably pretty easily. I don't get what I'm missing now that I'm looking at it again.
Right. I want to ask I want every edge under some certain thresholds. So I binary search. I remove all of the edges above that threshold.
I can check if every note is reachable.
That's fine.
But how do I know? I may need to delete extra edges still to adhere to this condition.
Why would I need a node to have an outgoing edge? If if I would need a node to have an outgoing edge, if this node is like an articulation point type of situation or what is it? If it's like a bridge, I don't need a node if it's I don't need an edge if it's not a bridge. But there's no way it's a problem about bridges because well it's also directed.
I think I get the idea. If if two nodes have outgoing edges to a node, I can remove I can remove like one of them, right? So every node only needs at most one incoming edge. That's the idea.
So I first strip out all of the edges above the certain weight.
Then for every node, can I just safely remove all incoming edges except for one?
And then I can check is it reachable.
What the hell did I do here?
I'm so dumb.
I think I just did it.
I just process one edge at a time.
I kind of want to test my idea though.
What do people say about binary search on the answer?
the threshold only applies to outgoing edges.
I didn't see that.
So when we reverse the graph obviously we only need one incoming edge turn or something like that.
one two years.
I want to I want to explore some ideas here.
We could binary search take a reversed graph.
Is it true that as long as every node is reachable?
Because we would we would form a tree if every note is reachable implicitly and the threshold is at least one. So this condition actually doesn't matter.
That's really smart.
Where's the If can't keep like this.
Less than equal to Okay. So, can we keep every edge less than or equal to x?
Sorry, I'm responding to something on the side here.
Let's build a new graph.
Call it add.
do. I think GMath I have like I have no idea what that is.
Um, sorry, I'm responding to somebody who is showing me some cool coding problems.
recommending a question.
Frog Traveler.
There was some light bulb question I really liked that I'm trying to find.
What was it called?
Wonderful light bulbs.
Wonderful light bulbs.
That was a really great problem.
Okay, back to this. So, we have our uh reversed edge map and we need to just see if we can reach the end.
cost.
See, can um If max something like this, All right.
Oh, wait.
I'm just doing a reachability query. Why did I even use Zyra?
It doesn't even matter. I guess I'll just test if it works.
Okay, but we don't even need dystra.
We can just do reachability.
We can just do a DFS.
Something like this.
Right.
Okay. Third bit faster. That's interesting. I like this thing about reversed edges. You can't You can't see my code. Sorry.
I need to I'll get a better streaming setup one day.
Um, now I'm seeing like a lot of a lot of thoughts about this.
I like this problem actually quite a bit. I also think it's kind of hard there.
Is it a cyclic? It wasn't right.
We have a weighted And every node that's at most threshold outgoing edge.
What is the max edge weight? can't cheat.
So, there's a few ways. Binary search on test X.
Rebuild the graph with only those edges to see if all nodes can reach node zero.
Every node having most threshold in the input means in our reversed graph every node has a most threshold input edges. Okay. And I want to think about this a bit more deeply. So every node has at most that many input edges.
And we're doing a reachability query, right? Why would I ever need to a reachability question? Have I seen the GFG daily problem? No.
Um didn't even know they had anything.
range LCM queries.
I've actually I've actually seen this not on GFG, but there's a code forces version.
Um, and I know something that's funny too is I think if you ask uh AI how to do range LCM queries, this is like with um it can't do it.
Wait, what are the is it like something maybe the one I saw is slightly different. Is this is it guaranteed that the output is small? Because the LCM can blow up, right? How does that work? Is there a mod?
Oh, mother vertex. Sorry, dude. If it's a graph problem, not going to be able to do it. I'm really bad at graphs. Um given a directed graph, a mother vertex is a vertex from which all other vertices can be reached.
Huh.
Um, can we can we decompose the graph into like strongly connected components and then build a new graph where one node in the new graph is a strongly connected component in the original and then try to topologically sort that.
Um and if we can topologically sort it then there is an answer and we can pick any node in the topological highest strongly connected component. Is that right?
Bro this whatever is the expected approach is like I'm not going to be able to do that.
That's It's some clever How to do this problem if it was a dag.
Can we not What is wrong with my strongly connected components approach?
I'm not super wellversed in that. So, I might have said something that's not doable or doesn't make any sense.
is graphs a weak point? Um, yeah. I'd say I'm pretty weak at graphs. I mean, I'm getting better now. I've been doing some hard graph problems, but yeah, pretty weak at graphs. I'm weak at stacks.
And we get constructive algorithms, ad hoc problems, uh, geometry. Geometry is like probably my worst, but it never comes up, so that's fine. Strong points are maybe I'm pretty good at trees, pretty good at data structures.
Um, I'm all right at DP, all right at like binary search usages.
Let's see what other what other topics are there.
Um these are all topics I've added. Yeah, I I think I'm quite strong at trees.
I know a lot of the uh decompositions, centrid demps, pretty good at binary lifting. What makes graphs harder for you? I mean, I think the ceiling on graph problems is just higher and I haven't done that. Haven't done that many, but I'm really bad on bracket problems.
I don't know if that counts as a topic.
What else is there?
Uh, I'm pretty good at game questions, I would say.
Uh, and and I'm good at primes, like average at combinotaurics.
I'm probably weak at math.
Yeah.
What else? Those are the main ones, I guess.
We can do something right.
Wait, I wanted to remove Well, no, actually that reduces What else? I did this different the first time.
What on earth was I doing here? Used like a heap or something.
Did I just do a single dyra? Oh, I get it.
Do I know Kosaraj's algorithm? I've done it like once. Can I increase spawn?
Yeah.
Um, what is that? That's um, is that for strongly connected components?
It's definitely not important.
I've done it once. I've done like Taran's all once or something. So, this is really smart. I use a reversed edge.
I process heat. I process edges in increasing order.
Yeah, I I want to work on that eventually. Like bridges, articulation points, strongly connected components.
I'm about all of those, but it's just it's low priority right now.
I'm really just wanting to get this stupid challenge over with to do every Leo problem because it's taking so much time.
So what am I doing here? I'm finding the minimum max.
I get what I'm doing. I'm trying to reach all nodes from node zero.
And I'm looking at I want to reach this node but like minimize the edges I used to get there.
How did I figure this out before? I must have been really dialed in because that's a pretty crazy uh idea.
build a reversed edge graph to solution is on smallest possible maximum edge weight lo total distance to reach.
Okay.
Okay, I should definitely reread both.
First solution is clever with threshold constraint. Second solution.
This is kind of giving me like minimum spanning tree vibes a little bit. That's a hard application of the extra.
You can add both solutions, right? because this one is way faster.
And then let's um yeah, we should put them both in GitHub binary search.
Get that extra solution in there.
Push that to GitHub.
So we have dystra and then binary search and answer.
It's like a somewhat hardish. The binary search aspect is not that hard, but I think the graph aspect is like pretty tricky.
Do you think BFS and DFS is enough um for graph problems? I don't really know. I mean, you don't need much.
Like, do they ask you dystras? I would probably just learn that. It's pretty simple. That's about it. Yeah, I don't think you need anything else.
Oh, I should update this.
add this to the dirt category.
How do I get my voice deeper?
I have no idea.
path with minimum effort.
We have heights of cells. We're in the top left. We want to go to the bottom right.
routes effort is the max absolute difference return the minimum effort okay so obviously we can binary search something so obviously you can binary search and then do like a path finding algorithm why did I have dystra in this.
All right, cuz each each edge is just a weight of course. So then we just like draw it's the same actually type of weight. What is the minimum weight on that?
Okay. So, yeah, dextra dextra is really cool on this.
It's actually the same exact idea. Oh, and union finds and we just union elements together in increasing edge order until uh the first and last note are unioned.
Nice solutions right there. Yeah, this is a nice problem. It's pretty easy.
That is a great that's a super instructive question. This is definitely going in the course and I think it's a nice problem.
to keep grinding.
You guys can't see what I'm doing.
This was an older problem I did. It's in the grass page.
Add it to GitHub 1631.
We can move in any direction of our path is the maximum distance.
What is the smallest effort?
test. Can we keep all efforts less than equal to X?
To test that, we do a DFS.
Each pair of cells they cost.
Was there anything else?
Union find dystra and binary search.
Very different.
part of application the extra think that binary search thing um matrix graph.
Sure.
What else do you find?
Did I have some offline find thing?
No.
It's also some tricky application and I should probably put that in the extra category.
This is like the same question.
Max score the score is the smallest value in that path.
That's the same same exact problem. They can be solved in every every same way. All right. They probably listed all of that.
What is K in this problem?
Is this even a valid solution? Hey, binary search. They probably listed Dextra and find. Yeah, it's the exact same thing.
Keep all nodes with the cost based on the minimum those two nodes.
Um, so we have these edges and we want to take we want to track the max.
Instead of a minimum, it's a maximum for our dystra.
And so when we pop the dyra, I think we use a max heap.
bottom mini. Just want to confirm that that's what they did.
Pop the largest value. Yeah.
The different instead of total pop weight, it tracks the the highest minimum edge.
And let me pop the next solve today's problem of the day.
Um, I'll have to look at it.
I would like to finish something else first.
What's it doing?
Must have added this already. No, I didn't. Okay.
Which Mac do I recommend? I'm on a Mac.
Yeah, I use a MacBook Pro.
Um, I have a maxed out one because I use four external monitors.
Um, yeah, I'm not going to do the puzzles today. Right now, I'm going to keep working on this direction to maximize the smallest cell.
I'll probably do it tomorrow. I'm going to have to do it tomorrow because I have to keep my streak, but I try to do four problems a day.
Oh jeez.
One more of the exact same category and then I should probably sleep.
I still have 1,083 problems from notion that I have to categorize.
That will put me at around 2400 problems.
And then I I've solved 3,300. So there's 900 more that I'm missing that I haven't even done that I'll have to add. And then I'm probably missing around 100 or actually less. Maybe like 20 or 30 questions on CSES.
So, what is that? Around 2,000 2,000 more problems I have to categorize.
Jeez, right, last last one. Then I got to get ready. Which language I'm using? I use Python and C++. Just depends on what I'm doing.
I remember this question in context. So we have to go from here to the bottom right. And then the safness factor is like we want to be far away from thieves.
Where is a thief?
Well, here we can only ever touch a thief. Exactly. So we just multissource BFS from every cell and then we want to minimize. I mean, yeah, it's like a nice question.
First multi-source BFS from thieves to find the distance to the we want to find a path from top left to bottom right.
And we can do that in all of these ways.
That's probably the exact same tags I should give.
No, I didn't give any tags to this problem.
do that binary search mat matrix reference you need to find what all the Okay, I probably don't need to reread notes for this.
If I have those other two already this repo that a text file push that to GitHub.
Is DSA not unnecessary? I don't know. I I just do coding problems because I like doing coding problems.
I can't uh I don't really like to think about this type of stuff to be honest.
like if if people want to do these problems to get into certain companies that's very understandable but I don't think I can give any useful advice around that because that's not the reason I do I practice multi-source breath for search it's not that confusing but They think that everything else is the same.
Like th with those questions, it depends so much on so many things. What are your goals? Where do you live? What is your experience? What things do you want to work on?
So, I don't I don't I can't give any useful advice without all of that context. Like you can give generic advice, but then it's generic. It's not really useful.
Like if you're asking, do you need to learn DSA if you want to work at companies that aren't fang?
It just it depends, right? Like depends on which company. Some companies ask algorithms, some don't. Usually there's also flexibility. You can tell them, you know, I'm good at algorithms, you should ask me them. I'm not good at them. I focus on building apps, you should look at that. Like, it entirely depends on the company. And so mo most things in life just depend on a lot of context.
What do I just do? 2812.
All right, I think that's enough.
How many did I even add today? I probably didn't even add enough, right? Because I pushed this to GitHub yesterday. Wait, that's fine. It's past 1:00 a.m. Beautiful array.
This was a permutations thing. This was like an impossible question.
Tickets skipping.
This is like the first problem I did today, I think.
Yeah.
So, I added only 17 today. That's fine.
Yo, what's up, James? Am I drinking coffee? I No, I'm drinking tea. I don't I don't really drink coffee because I have an autoimmune disease that affects my stomach.
Yeah, I'm grinding. I'm adding I'm adding problems that I've already solved to my database because I need to back through a lot of stuff. Okay, I'll do like maybe one, two more. Think this is missing.
What did I What even was this?
I really should have done this the first time I solved all of these questions.
Now I have to reread every single problem.
Okay, so each villager has a grumpiness.
We need to select two villagers and give them emeralds to share and their grumpiness goes down.
And we need to union all villagers together.
Why does this grumpiness go down? What does it even mean?
Oh, wait. This is the grumpiness.
So, I can't like understand this right now. My mind is kind of fried even though this is literally an 800 and I'm looking at my notes already and it just says basic 3D logic.
Yeah, not as not as late tonight.
I'm going to look for like one more question that I've solved.
I'm looking through my notes, but Maybe this one.
We have two arrays and we'll choose a random one where a is bigger and then choose a random one where a is smaller.
How many iterations occur?
Well, we could just brute force for we just count for every position.
If step one is ignored, it will end.
So what this runs one time, this has the capability to run three times. Okay. So it's just like a max sort of comparison.
Looks like I did this while loop simulation.
Yeah, I mean I did this in the contest.
I'm just uh I'm trying to add problems that I've solved already.
Even though it's a little bit taxing, just consistently do it every day and it will finish them all.
So they probably just did a like a count up and then do a max thing, right?
That makes sense.
They do that plus one, right?
to add this ones to collapse this tab.
this into the code forces folder.
Commit to GitHub and that um simulation, but it's not That's like a barely used aspect of the question.
Can you turn on music? I'm going to head out in a sec.
I think I'm done.
Almost hit 20. That's okay. I'll leave it a few short. I'm like two short from today.
Three short. But it's good progress. Especially these all of these code forces ones take longer to categorize and like some of these were really really rough because this was a new topic this problem.
Okay, I'm going to go. I'm gonna go sleep.
Ähnliche Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
Re: 🗣️📍theprophedu📍2026 GST 103 CLASS (E-EXAM REVISION)
theprophedu
636 views•2026-06-04
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Instagram accounts got PWNed
EricParker
13K views•2026-06-03











