Generate WORKING Manim code for Scene 1.

IMPLEMENTATION: Certainly! Below is a detailed **plan implementation** for the scene following your strict positioning, object, animation, color, and cleanup rules.

---

## Layout Plan

1. **Title**:  
   - Object: `Text("Minimum Spanning Tree (MST)")`  
   - Position: `.to_edge(UP, buff=0.5)`  
   - Purpose: Scene title at the top edge.

2. **Main Equation (Definition of Spanning Tree)**:  
   - Object: `MathTex(r"\text{Spanning Tree} = \{\text{subset of edges}\mid \text{connect all vertices, no cycles}\}")`  
   - Position: `.shift(UP * 1.5)`  
   - Purpose: Define spanning tree concept, upper center.

3. **Secondary Text (Explanation of MST)**:  
   - Object: `Text("Minimum Spanning Tree: spanning tree with smallest total edge weight")`  
   - Position: `.shift(DOWN * 1.5)`  
   - Purpose: Explain MST concept, lower center.

4. **Example Graph (Left side)**:  
   - Objects:  
     - `Circle` for nodes (4-5 nodes)  
     - `Line` for edges with `MathTex` weights near edges  
     - `Dot` for nodes  
   - Position: `.shift(LEFT * 2.5)`  
   - Purpose: Show a weighted undirected graph example.

5. **Highlight MST on Example Graph (Right side)**:  
   - Objects:  
     - Same nodes and edges as example graph but highlight MST edges with `Line` in GREEN  
     - Use `SurroundingRectangle` or `Rectangle` to emphasize MST edges/nodes  
   - Position: `.shift(RIGHT * 2.5)`  
   - Purpose: Conceptually highlight MST edges on the same example graph.

6. **Problem Statement (Secondary Text)**:  
   - Object: `Text("Problem: Given a weighted graph, find the MST efficiently")`  
   - Position: `.shift(DOWN * 1.5)`  
   - Purpose: State the MST problem, lower center.

7. **Transition Text (Secondary Text)**:  
   - Object: `Text("Kruskal's Algorithm: A method to find MST")`  
   - Position: `.shift(DOWN * 1.5)`  
   - Purpose: Transition to Kruskal’s algorithm, lower center.

---

## Animation Sequence

### Step 1: Introduce Title and Spanning Tree Definition

- **Action**:  
  - `Write` the Title (Element 1)  
  - `Write` the Spanning Tree Definition (Element 2)  
- **Duration**: 3 seconds  
- **Cleanup**: None (keep both visible)

---

### Step 2: Explain MST Concept

- **Action**:  
  - `Write` the MST Explanation (Element 3)  
- **Duration**: 3 seconds  
- **Cleanup**: None (keep Title and Spanning Tree Definition visible)

---

### Step 3: Show Example Graph and Highlight MST

- **Action**:  
  - `Create` the Example Graph (Element 4) on left side  
  - `Create` the Highlighted MST on right side (Element 5)  
- **Duration**: 4 seconds  
- **Cleanup**:  
  - `FadeOut` MST Explanation (Element 3)  
  - Keep Title and Spanning Tree Definition visible  
  - Keep example graph and MST highlight visible

---

### Step 4: State Problem and Transition to Kruskal’s Algorithm

- **Action**:  
  - `FadeOut` Example Graph and MST Highlight (Elements 4 & 5)  
  - `FadeOut` Spanning Tree Definition (Element 2)  
  - `Write` Problem Statement (Element 6)  
- **Duration**: 3 seconds  
- **Cleanup**:  
  - `FadeOut` Problem Statement (Element 6)  
  - `Write` Transition Text (Element 7)  
- **Final Cleanup**:  
  - Keep Title and Transition Text visible for next scene

---

## Summary Table

| Step | Action Description                                  | Objects Involved                        | Animations          | Cleanup                                  |
|-------|---------------------------------------------------|---------------------------------------|---------------------|------------------------------------------|
| 1     | Write Title and Spanning Tree Definition          | Title (Text), Spanning Tree (MathTex) | Write               | None                                     |
| 2     | Write MST Explanation                              | MST Explanation (Text)                 | Write               | None                                     |
| 3     | Create Example Graph (left) and Highlight MST (right) | Circles, Lines, Dots, Weights, Highlights | Create              | FadeOut MST Explanation                   |
| 4     | FadeOut graphs and definition, Write Problem and Transition | Problem Statement (Text), Transition Text (Text) | FadeOut, Write      | FadeOut Problem Statement, keep Title & Transition |

---

## Notes on Implementation

- **Graph Construction**:  
  - Use `Circle` and `Dot` for nodes, positioned relative to `.shift(LEFT * 2.5)` or `.shift(RIGHT * 2.5)`  
  - Use `Line` for edges, with `MathTex` weights placed near edges in WHITE color  
  - MST edges highlighted in GREEN lines on right side graph

- **Colors**:  
  - Title: WHITE  
  - Spanning Tree Definition: BLUE  
  - MST Explanation: YELLOW  
  - Graph nodes: WHITE dots  
  - Graph edges: WHITE lines  
  - MST edges: GREEN lines  
  - Weights: WHITE  
  - Problem and Transition Text: RED or WHITE for emphasis

- **Positioning**:  
  - Strictly follow `.to_edge(UP, buff=0.5)`, `.shift(UP * 1.5)`, `.shift(DOWN * 1.5)`, `.shift(LEFT * 2.5)`, `.shift(RIGHT * 2.5)`  
  - No element shifted beyond +/-3 units in any direction  
  - All elements fit within screen bounds (-6 to +6 horizontal, -3.5 to +3.5 vertical)

---

If you want, I can also provide the exact Manim code snippet implementing this plan. Would you like 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: