Generate WORKING Manim code for Scene 1.

IMPLEMENTATION: Certainly! Below is a detailed **plan implementation** for the scene following your **strict positioning rules**, allowed objects, animations, colors, and cleanup instructions.

---

## Layout Plan

1. **Title**  
   - Object type: `Text`  
   - Position method: `.to_edge(UP, buff=0.5)`  
   - Purpose: Scene title "Understanding Dijkstra’s Algorithm"

2. **Main equation / key statement**  
   - Object type: `MathTex` or `Text` (depending on content)  
   - Position method: `.shift(UP * 1.5)`  
   - Purpose: Key concept or formula related to shortest path problem

3. **Graph visualization**  
   - Object types: `Circle` (nodes), `Line` or `Arrow` (edges), `Text` (weights)  
   - Position method: `.shift(LEFT * 2.5)` (left side)  
   - Purpose: Show a simple weighted graph with labeled nodes and edges

4. **Secondary descriptive text**  
   - Object type: `Text`  
   - Position method: `.shift(DOWN * 1.5)`  
   - Purpose: Explanation or definition of shortest path problem or algorithm notes

5. **Additional notes or emphasis**  
   - Object type: `Text` or `MathTex`  
   - Position method: `.shift(RIGHT * 2.5)`  
   - Purpose: Emphasize non-negative weights and transition to algorithm

---

## Animation Sequence

### Step 1: Introduce the title and graph concept

- **Elements:**  
  - Title (`Text`): "Understanding Dijkstra’s Algorithm" -> `.to_edge(UP, buff=0.5)`  
  - Graph visualization (nodes and edges with weights) -> `.shift(LEFT * 2.5)`  
  - Secondary text (introduce graphs: nodes and edges) -> `.shift(DOWN * 1.5)`

- **Animations:**  
  - `Write(title)` - 2 sec  
  - `Create(graph elements)` - 3 sec  
  - `Write(secondary_text)` - 3 sec

- **Cleanup:**  
  - FadeOut(secondary_text)  
  - Keep title and graph visible

---

### Step 2: Explain shortest path problem

- **Elements:**  
  - Main equation / key statement (e.g. "Find shortest path from start node to all others") -> `.shift(UP * 1.5)`  
  - Secondary text (explain shortest path problem) -> `.shift(DOWN * 1.5)`

- **Animations:**  
  - `Write(main_equation)` - 3 sec  
  - `Write(secondary_text)` - 3 sec

- **Cleanup:**  
  - FadeOut(secondary_text)  
  - Keep title, graph, main_equation visible

---

### Step 3: Emphasize non-negative weights and transition

- **Elements:**  
  - Secondary text (emphasize weights >= 0) -> `.shift(DOWN * 1.5)`  
  - Additional note (e.g. "This condition is crucial for Dijkstra’s algorithm") -> `.shift(RIGHT * 2.5)`

- **Animations:**  
  - `Write(secondary_text)` - 3 sec  
  - `Write(additional_note)` - 3 sec

- **Cleanup:**  
  - FadeOut(secondary_text)  
  - FadeOut(additional_note)  
  - Keep title, graph, main_equation visible

---

### Step 4: Transition to algorithm introduction

- **Elements:**  
  - Secondary text (transition statement) -> `.shift(DOWN * 1.5)`  
    e.g. "Next: Efficient step-by-step method to find shortest paths"

- **Animations:**  
  - `Write(secondary_text)` - 3 sec

- **Cleanup:**  
  - FadeOut(secondary_text)  
  - FadeOut(graph)  
  - FadeOut(main_equation)  
  - FadeOut(title)  
  - Scene ends cleanly

---

## Detailed Element Examples

### Graph (LEFT side, `.shift(LEFT * 2.5)`)

- Nodes: 3-4 circles labeled A, B, C, D  
- Edges: Lines or Arrows with positive weights (e.g. 2, 5, 1) in `YELLOW` or `WHITE`  
- Node labels: `Text` in `BLUE` or `WHITE` near each node  
- Edge weights: `Text` in `YELLOW` near edges

### Text examples

- Title: `"Understanding Dijkstra’s Algorithm"` in `WHITE`  
- Secondary text: `"Graphs consist of nodes connected by edges with weights."` in `WHITE`  
- Main equation: `"Shortest path: minimize total edge weights from start node"` in `GREEN` or `MathTex` if formulaic  
- Emphasis text: `"Weights must be non-negative (>= 0)"` in `RED`  
- Transition text: `"Next: Efficient step-by-step method to find shortest paths"` in `BLUE`

---

If you want, I can provide the **exact Manim code snippet** implementing this plan with strict positioning and allowed objects/colors/animations. Would you like me to do that?
PATTERN: function_graph

CRITICAL CONSTRAINTS:
1. Use ONLY these objects: Text, MathTex, Axes, Circle, Rectangle, Line, Arrow, Dot, SurroundingRectangle, VGroup
2. Use ONLY these animations: Write, Create, FadeIn, FadeOut 
3. Use ONLY these colors (no quotes): BLUE, RED, GREEN, YELLOW, WHITE, ORANGE, PURPLE
4. NO undefined objects like VideoFile, Slider, ImageMobject
5. NO Unicode characters - use LaTeX: \sqrt{} not √, \pm not ±

POSITIONING REQUIREMENTS (CRITICAL):
- Each element MUST have unique position within screen bounds
- SAFE positions only: .to_edge(UP), .shift(UP*1.5), .shift(DOWN*1.5), .shift(LEFT*2.5), .shift(RIGHT*2.5)
- NO extreme shifts: avoid UP*3, DOWN*3, LEFT*4, RIGHT*4 (goes off-screen)
- NO overlapping: if one element uses .shift(UP*1.5), others must use different positions
- Test positions: Title=top, Main=upper center, Secondary=lower center, Sides=left/right

TEMPLATE TO ADAPT:

        # Title at top
        title = Text("{title}").scale(0.8).to_edge(UP, buff=0.5)
        
        # Axes positioned in lower area
        axes = Axes(
            x_range=[-3, 3, 1],
            y_range=[-2, 4, 1], 
            x_length=6,
            y_length=4,
            axis_config={{"color": BLUE}}
        ).shift(DOWN * 0.5)
        
        # Function plot
        function = axes.plot(lambda x: {function_expr}, color=RED)
        
        # Equation display
        equation = MathTex(r"{equation}").shift(UP * 1.5)
        
        # Animation sequence
        self.play(Write(title))
        self.wait(1)
        self.play(Write(equation))
        self.wait(1)
        self.play(Create(axes))
        self.wait(1)
        self.play(Create(function))
        self.wait(2)
                

Replace placeholders with scene-specific values and ensure working Manim code.

Generate complete Python code:
SMART POSITIONING REQUIREMENTS:
- Analyze the content TYPE first: equation, diagram, comparison, process
- Position based on content meaning, not just arbitrary rules
- Main subject (equation/diagram) should be CENTER or slightly UP
- Supporting text should be BELOW the main subject
- Comparisons should use LEFT/RIGHT positioning
- Sequential content should use TOP-to-BOTTOM flow
- NEVER fade out main content - only temporary highlights

CAREFULLY IMPLEMENT THIS