{"category": "web_design_responsive_grid", "lang": "html_css_js", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert frontend architect specializing in responsive CSS Grid, accessible ARIA semantics, and zero-jank interactive UI."}, {"role": "user", "content": "Build a responsive, accessible SaaS Analytics Dashboard layout using CSS custom properties (`:root` + `[data-theme=\"dark\"]`), auto-fit CSS Grid (`minmax(320px, 1fr)`), keyboard-accessible filter tabs, and a mobile `@media` breakpoint."}, {"role": "assistant", "content": "```html\n\n\n\n\n\nSaaS Analytics Dashboard\n\n\n\n
\n
\n

SaaS Analytics Dashboard

\n
\n \n \n
\n
\n
\n

Metric 1

Live telemetry active

\n

Metric 2

Live telemetry active

\n

Metric 3

Live telemetry active

\n
\n
\n\n\n\n```"}]} {"category": "web_design_responsive_grid", "lang": "html_css_js", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert frontend architect specializing in responsive CSS Grid, accessible ARIA semantics, and zero-jank interactive UI."}, {"role": "user", "content": "Build a responsive, accessible AI Developer Studio layout using CSS custom properties (`:root` + `[data-theme=\"dark\"]`), auto-fit CSS Grid (`minmax(280px, 1fr)`), keyboard-accessible filter tabs, and a mobile `@media` breakpoint."}, {"role": "assistant", "content": "```html\n\n\n\n\n\nAI Developer Studio\n\n\n\n
\n
\n

AI Developer Studio

\n
\n \n \n
\n
\n
\n

Metric 1

Live telemetry active

\n

Metric 2

Live telemetry active

\n

Metric 3

Live telemetry active

\n

Metric 4

Live telemetry active

\n
\n
\n\n\n\n```"}]} {"category": "web_design_responsive_grid", "lang": "html_css_js", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert frontend architect specializing in responsive CSS Grid, accessible ARIA semantics, and zero-jank interactive UI."}, {"role": "user", "content": "Build a responsive, accessible Fintech Real-Time Ledger layout using CSS custom properties (`:root` + `[data-theme=\"dark\"]`), auto-fit CSS Grid (`minmax(300px, 1fr)`), keyboard-accessible filter tabs, and a mobile `@media` breakpoint."}, {"role": "assistant", "content": "```html\n\n\n\n\n\nFintech Real-Time Ledger\n\n\n\n
\n
\n

Fintech Real-Time Ledger

\n
\n \n \n
\n
\n
\n

Metric 1

Live telemetry active

\n

Metric 2

Live telemetry active

\n

Metric 3

Live telemetry active

\n
\n
\n\n\n\n```"}]} {"category": "web_design_responsive_grid", "lang": "html_css_js", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert frontend architect specializing in responsive CSS Grid, accessible ARIA semantics, and zero-jank interactive UI."}, {"role": "user", "content": "Build a responsive, accessible Cloud GPU Control Plane layout using CSS custom properties (`:root` + `[data-theme=\"dark\"]`), auto-fit CSS Grid (`minmax(260px, 1fr)`), keyboard-accessible filter tabs, and a mobile `@media` breakpoint."}, {"role": "assistant", "content": "```html\n\n\n\n\n\nCloud GPU Control Plane\n\n\n\n
\n
\n

Cloud GPU Control Plane

\n
\n \n \n
\n
\n
\n

Metric 1

Live telemetry active

\n

Metric 2

Live telemetry active

\n

Metric 3

Live telemetry active

\n

Metric 4

Live telemetry active

\n
\n
\n\n\n\n```"}]} {"category": "web_design_responsive_grid", "lang": "html_css_js", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert frontend architect specializing in responsive CSS Grid, accessible ARIA semantics, and zero-jank interactive UI."}, {"role": "user", "content": "Build a responsive, accessible Healthcare Triage Portal layout using CSS custom properties (`:root` + `[data-theme=\"dark\"]`), auto-fit CSS Grid (`minmax(310px, 1fr)`), keyboard-accessible filter tabs, and a mobile `@media` breakpoint."}, {"role": "assistant", "content": "```html\n\n\n\n\n\nHealthcare Triage Portal\n\n\n\n
\n
\n

Healthcare Triage Portal

\n
\n \n \n
\n
\n
\n

Metric 1

Live telemetry active

\n

Metric 2

Live telemetry active

\n

Metric 3

Live telemetry active

\n
\n
\n\n\n\n```"}]} {"category": "web_design_responsive_grid", "lang": "html_css_js", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert frontend architect specializing in responsive CSS Grid, accessible ARIA semantics, and zero-jank interactive UI."}, {"role": "user", "content": "Build a responsive, accessible E-Commerce Bento Storefront layout using CSS custom properties (`:root` + `[data-theme=\"dark\"]`), auto-fit CSS Grid (`minmax(290px, 1fr)`), keyboard-accessible filter tabs, and a mobile `@media` breakpoint."}, {"role": "assistant", "content": "```html\n\n\n\n\n\nE-Commerce Bento Storefront\n\n\n\n
\n
\n

E-Commerce Bento Storefront

\n
\n \n \n
\n
\n
\n

Metric 1

Live telemetry active

\n

Metric 2

Live telemetry active

\n

Metric 3

Live telemetry active

\n

Metric 4

Live telemetry active

\n
\n
\n\n\n\n```"}]} {"category": "web_design_interactive", "lang": "typescript_html_css", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert web UI & frontend systems engineer."}, {"role": "user", "content": "Write HTML + vanilla JavaScript for an accessible modal dialog (`role=\"dialog\"`, `aria-modal=\"true\"`) that closes on `Escape` keydown and restores focus to the trigger button."}, {"role": "assistant", "content": "```html\n\n\n\n```"}]} {"category": "web_design_interactive", "lang": "typescript_html_css", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert web UI & frontend systems engineer."}, {"role": "user", "content": "Fix the infinite re-render loop in this React `useEffect` hook that fetches user projects and updates state on every render:\n```tsx\nuseEffect(() => {\n fetchProjects({ filter }).then((items) => setProjects([...items]));\n});\n```"}, {"role": "assistant", "content": "The infinite loop happens because `useEffect` omits its dependency array (so it runs after *every* `setProjects` state update) and lacks an `AbortController` cleanup.\n\n```tsx\nuseEffect(() => {\n const controller = new AbortController();\n let cancelled = false;\n\n fetchProjects({ filter, signal: controller.signal })\n .then((items) => {\n if (!cancelled) setProjects(items);\n })\n .catch((err) => {\n if (err.name !== 'AbortError') console.error(err);\n });\n\n return () => {\n cancelled = true;\n controller.abort();\n };\n}, [filter]);\n```"}]} {"category": "web_design_interactive", "lang": "typescript_html_css", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert web UI & frontend systems engineer."}, {"role": "user", "content": "Write a clean, cancellation-safe TypeScript `debounce` utility that preserves `this` context, full argument types, and exposes a `.cancel()` method to prevent timer leaks on component unmount."}, {"role": "assistant", "content": "```ts\nexport interface DebouncedFn {\n (...args: Args): void;\n cancel(): void;\n}\n\nexport function debounce(\n fn: (...args: Args) => void,\n delayMs: number,\n): DebouncedFn {\n let timer: ReturnType | undefined;\n const wrapped = function (this: unknown, ...args: Args) {\n if (timer !== undefined) clearTimeout(timer);\n timer = setTimeout(() => {\n timer = undefined;\n fn.apply(this, args);\n }, delayMs);\n } as DebouncedFn;\n\n wrapped.cancel = () => {\n if (timer !== undefined) {\n clearTimeout(timer);\n timer = undefined;\n }\n };\n return wrapped;\n}\n```"}]} {"category": "loop_fixing_bug_repair", "lang": "python", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert python debugging and termination-safety engineer."}, {"role": "user", "content": "Fix the infinite loop in upper-bound binary search when `lo + 1 == hi`:\n```python\ndef last_true(lo: int, hi: int, pred) -> int:\n while lo < hi:\n mid = (lo + hi) // 2\n if pred(mid):\n lo = mid\n else:\n hi = mid - 1\n return lo if pred(lo) else -1\n```"}, {"role": "assistant", "content": "When `lo = mid` is used in the `True` branch, integer floor division `(lo + hi) // 2` evaluates to `lo` whenever `hi == lo + 1`, causing an infinite loop. Bias `mid` upward with `(lo + hi + 1) // 2`:\n\n```python\ndef last_true(lo: int, hi: int, pred) -> int:\n if lo > hi:\n return -1\n while lo < hi:\n mid = (lo + hi + 1) // 2 # Upper-mid prevents lo == mid stall!\n if pred(mid):\n lo = mid\n else:\n hi = mid - 1\n return lo if pred(lo) else -1\n```"}]} {"category": "loop_fixing_bug_repair", "lang": "python", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert python debugging and termination-safety engineer."}, {"role": "user", "content": "Fix the sliding-window infinite `while` loop when shrinking duplicate characters:\n```python\ndef longest_unique(s: str) -> int:\n seen = set()\n left = 0\n ans = 0\n for right, ch in enumerate(s):\n while ch in seen:\n seen.discard(s[right]) # BUG!\n seen.add(ch)\n ans = max(ans, right - left + 1)\n return ans\n```"}, {"role": "assistant", "content": "The inner `while` loop must remove `s[left]` and increment `left += 1` until `ch` leaves the window:\n\n```python\ndef longest_unique(s: str) -> int:\n seen: set[str] = set()\n left = 0\n ans = 0\n for right, ch in enumerate(s):\n while ch in seen:\n seen.remove(s[left])\n left += 1\n seen.add(ch)\n ans = max(ans, right - left + 1)\n return ans\n```"}]} {"category": "loop_fixing_bug_repair", "lang": "rust", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert rust debugging and termination-safety engineer."}, {"role": "user", "content": "Fix the Rust integer underflow panic / infinite downward loop when iterating backwards to index `0` on `usize`:\n```rust\npub fn reverse_scan(xs: &[i32], target: i32) -> Option {\n let mut i = xs.len() - 1; // panics on empty slice, and `i -= 1` panics/wraps at 0!\n while i >= 0 {\n if xs[i] == target { return Some(i); }\n i -= 1;\n }\n None\n}\n```"}, {"role": "assistant", "content": "`usize` is unsigned, so `xs.len() - 1` underflows on empty slices and `i >= 0` is always true (`i -= 1` at `0` panics in debug or wraps to `usize::MAX` in release, causing an infinite loop/OOB). Use `(0..xs.len()).rev()`:\n\n```rust\npub fn reverse_scan(xs: &[i32], target: i32) -> Option {\n for i in (0..xs.len()).rev() {\n if xs[i] == target {\n return Some(i);\n }\n }\n None\n}\n```"}]} {"category": "loop_fixing_bug_repair", "lang": "cpp", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert cpp debugging and termination-safety engineer."}, {"role": "user", "content": "Fix the C++20 iterator-invalidation / skipped-element loop bug when erasing even integers from `std::vector`:\n```cpp\n#include \nvoid erase_evens(std::vector& v) {\n for (auto it = v.begin(); it != v.end(); ++it) {\n if (*it % 2 == 0) v.erase(it);\n }\n}\n```"}, {"role": "assistant", "content": "`v.erase(it)` invalidates `it`, so incrementing `++it` afterward triggers undefined behavior and skips adjacent elements. Assign `it = v.erase(it)` only when erasing (or use C++20 `std::erase_if`):\n\n```cpp\n#include \n\nvoid erase_evens(std::vector& v) {\n std::erase_if(v, [](int x) { return x % 2 == 0; });\n}\n```"}]} {"category": "loop_fixing_bug_repair", "lang": "go", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert go debugging and termination-safety engineer."}, {"role": "user", "content": "Fix the Go goroutine leak & unclosed channel deadlock loop in this worker fan-out:\n```go\nfunc SquareAll(nums []int) []int {\n ch := make(chan int)\n for _, n := range nums {\n go func(v int) { ch <- v * v }(n)\n }\n var out []int\n for v := range ch { // DEADLOCK: ch is never closed!\n out = append(out, v)\n }\n return out\n}\n```"}, {"role": "assistant", "content": "`for v := range ch` blocks forever unless `ch` is closed after all goroutines finish. Track completion with `sync.WaitGroup` and close `ch` in a coordinator goroutine:\n\n```go\npackage main\n\nimport \"sync\"\n\nfunc SquareAll(nums []int) []int {\n ch := make(chan int, len(nums))\n var wg sync.WaitGroup\n for _, n := range nums {\n wg.Add(1)\n go func(v int) {\n defer wg.Done()\n ch <- v * v\n }(n)\n }\n go func() {\n wg.Wait()\n close(ch)\n }()\n out := make([]int, 0, len(nums))\n for v := range ch {\n out = append(out, v)\n }\n return out\n}\n```"}]} {"category": "loop_fixing_bug_repair", "lang": "python", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert python debugging and termination-safety engineer."}, {"role": "user", "content": "Fix the infinite retry loop in an AI agent tool-execution harness when a tool keeps returning a deterministic error:\n```python\ndef run_agent_step(llm, tools, messages):\n while True:\n reply = llm(messages)\n if not reply.tool_calls:\n return reply.text\n for tc in reply.tool_calls:\n out = tools.run(tc)\n messages.append({'role': 'tool', 'content': out})\n```"}, {"role": "assistant", "content": "Bound total steps (`max_steps`) AND detect repeated identical `(tool_name, canonical_args)` failures with a circuit-breaker signature set so the agent halts or switches strategy instead of looping forever:\n\n```python\nimport json\n\ndef run_agent_step(llm, tools, messages, max_steps: int = 8) -> str:\n seen_failures: dict[str, int] = {}\n for _ in range(max_steps):\n reply = llm(messages)\n if not reply.tool_calls:\n return reply.text\n for tc in reply.tool_calls:\n sig = f\"{tc.name}:{json.dumps(tc.args, sort_keys=True)}\"\n if seen_failures.get(sig, 0) >= 2:\n messages.append({\n 'role': 'user',\n 'content': f'CircuitBreaker: repeated failing call {sig} blocked. Answer using existing context.',\n })\n continue\n ok, out = tools.run_checked(tc)\n if not ok:\n seen_failures[sig] = seen_failures.get(sig, 0) + 1\n messages.append({'role': 'user', 'content': f'{out}'})\n return 'Max agent steps reached; returning best partial progress.'\n```"}]} {"category": "loop_fixing_bug_repair", "lang": "python", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert algorithm & loop-termination engineer."}, {"role": "user", "content": "Fix the cycle-induced infinite BFS loop on a directed graph with up to 15 nodes when computing shortest distance from `src` to `dst`."}, {"role": "assistant", "content": "Mark nodes in `visited` **at enqueue time** (not dequeue time) so cycles never re-enqueue visited vertices and queue size stays $O(V)$:\n\n```python\nfrom collections import deque\n\ndef bfs_shortest_path(adj: dict[int, list[int]], src: int, dst: int) -> int:\n if src == dst:\n return 0\n visited = {src}\n q = deque([(src, 0)])\n while q:\n u, d = q.popleft()\n for v in adj.get(u, ()):\n if v == dst:\n return d + 1\n if v not in visited:\n visited.add(v)\n q.append((v, d + 1))\n return -1\n```"}]} {"category": "loop_fixing_bug_repair", "lang": "python", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert algorithm & loop-termination engineer."}, {"role": "user", "content": "Fix the cycle-induced infinite BFS loop on a directed graph with up to 20 nodes when computing shortest distance from `src` to `dst`."}, {"role": "assistant", "content": "Mark nodes in `visited` **at enqueue time** (not dequeue time) so cycles never re-enqueue visited vertices and queue size stays $O(V)$:\n\n```python\nfrom collections import deque\n\ndef bfs_shortest_path(adj: dict[int, list[int]], src: int, dst: int) -> int:\n if src == dst:\n return 0\n visited = {src}\n q = deque([(src, 0)])\n while q:\n u, d = q.popleft()\n for v in adj.get(u, ()):\n if v == dst:\n return d + 1\n if v not in visited:\n visited.add(v)\n q.append((v, d + 1))\n return -1\n```"}]} {"category": "loop_fixing_bug_repair", "lang": "python", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert algorithm & loop-termination engineer."}, {"role": "user", "content": "Fix the cycle-induced infinite BFS loop on a directed graph with up to 25 nodes when computing shortest distance from `src` to `dst`."}, {"role": "assistant", "content": "Mark nodes in `visited` **at enqueue time** (not dequeue time) so cycles never re-enqueue visited vertices and queue size stays $O(V)$:\n\n```python\nfrom collections import deque\n\ndef bfs_shortest_path(adj: dict[int, list[int]], src: int, dst: int) -> int:\n if src == dst:\n return 0\n visited = {src}\n q = deque([(src, 0)])\n while q:\n u, d = q.popleft()\n for v in adj.get(u, ()):\n if v == dst:\n return d + 1\n if v not in visited:\n visited.add(v)\n q.append((v, d + 1))\n return -1\n```"}]} {"category": "loop_fixing_bug_repair", "lang": "python", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert algorithm & loop-termination engineer."}, {"role": "user", "content": "Fix the cycle-induced infinite BFS loop on a directed graph with up to 30 nodes when computing shortest distance from `src` to `dst`."}, {"role": "assistant", "content": "Mark nodes in `visited` **at enqueue time** (not dequeue time) so cycles never re-enqueue visited vertices and queue size stays $O(V)$:\n\n```python\nfrom collections import deque\n\ndef bfs_shortest_path(adj: dict[int, list[int]], src: int, dst: int) -> int:\n if src == dst:\n return 0\n visited = {src}\n q = deque([(src, 0)])\n while q:\n u, d = q.popleft()\n for v in adj.get(u, ()):\n if v == dst:\n return d + 1\n if v not in visited:\n visited.add(v)\n q.append((v, d + 1))\n return -1\n```"}]} {"category": "loop_fixing_bug_repair", "lang": "python", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert algorithm & loop-termination engineer."}, {"role": "user", "content": "Fix the cycle-induced infinite BFS loop on a directed graph with up to 35 nodes when computing shortest distance from `src` to `dst`."}, {"role": "assistant", "content": "Mark nodes in `visited` **at enqueue time** (not dequeue time) so cycles never re-enqueue visited vertices and queue size stays $O(V)$:\n\n```python\nfrom collections import deque\n\ndef bfs_shortest_path(adj: dict[int, list[int]], src: int, dst: int) -> int:\n if src == dst:\n return 0\n visited = {src}\n q = deque([(src, 0)])\n while q:\n u, d = q.popleft()\n for v in adj.get(u, ()):\n if v == dst:\n return d + 1\n if v not in visited:\n visited.add(v)\n q.append((v, d + 1))\n return -1\n```"}]} {"category": "loop_fixing_bug_repair", "lang": "python", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert algorithm & loop-termination engineer."}, {"role": "user", "content": "Fix the cycle-induced infinite BFS loop on a directed graph with up to 40 nodes when computing shortest distance from `src` to `dst`."}, {"role": "assistant", "content": "Mark nodes in `visited` **at enqueue time** (not dequeue time) so cycles never re-enqueue visited vertices and queue size stays $O(V)$:\n\n```python\nfrom collections import deque\n\ndef bfs_shortest_path(adj: dict[int, list[int]], src: int, dst: int) -> int:\n if src == dst:\n return 0\n visited = {src}\n q = deque([(src, 0)])\n while q:\n u, d = q.popleft()\n for v in adj.get(u, ()):\n if v == dst:\n return d + 1\n if v not in visited:\n visited.add(v)\n q.append((v, d + 1))\n return -1\n```"}]} {"category": "loop_fixing_bug_repair", "lang": "python", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert algorithm & loop-termination engineer."}, {"role": "user", "content": "Fix the cycle-induced infinite BFS loop on a directed graph with up to 45 nodes when computing shortest distance from `src` to `dst`."}, {"role": "assistant", "content": "Mark nodes in `visited` **at enqueue time** (not dequeue time) so cycles never re-enqueue visited vertices and queue size stays $O(V)$:\n\n```python\nfrom collections import deque\n\ndef bfs_shortest_path(adj: dict[int, list[int]], src: int, dst: int) -> int:\n if src == dst:\n return 0\n visited = {src}\n q = deque([(src, 0)])\n while q:\n u, d = q.popleft()\n for v in adj.get(u, ()):\n if v == dst:\n return d + 1\n if v not in visited:\n visited.add(v)\n q.append((v, d + 1))\n return -1\n```"}]} {"category": "loop_fixing_bug_repair", "lang": "python", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert algorithm & loop-termination engineer."}, {"role": "user", "content": "Fix the cycle-induced infinite BFS loop on a directed graph with up to 50 nodes when computing shortest distance from `src` to `dst`."}, {"role": "assistant", "content": "Mark nodes in `visited` **at enqueue time** (not dequeue time) so cycles never re-enqueue visited vertices and queue size stays $O(V)$:\n\n```python\nfrom collections import deque\n\ndef bfs_shortest_path(adj: dict[int, list[int]], src: int, dst: int) -> int:\n if src == dst:\n return 0\n visited = {src}\n q = deque([(src, 0)])\n while q:\n u, d = q.popleft()\n for v in adj.get(u, ()):\n if v == dst:\n return d + 1\n if v not in visited:\n visited.add(v)\n q.append((v, d + 1))\n return -1\n```"}]} {"category": "loop_fixing_bug_repair", "lang": "python", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert algorithm & loop-termination engineer."}, {"role": "user", "content": "Fix the cycle-induced infinite BFS loop on a directed graph with up to 55 nodes when computing shortest distance from `src` to `dst`."}, {"role": "assistant", "content": "Mark nodes in `visited` **at enqueue time** (not dequeue time) so cycles never re-enqueue visited vertices and queue size stays $O(V)$:\n\n```python\nfrom collections import deque\n\ndef bfs_shortest_path(adj: dict[int, list[int]], src: int, dst: int) -> int:\n if src == dst:\n return 0\n visited = {src}\n q = deque([(src, 0)])\n while q:\n u, d = q.popleft()\n for v in adj.get(u, ()):\n if v == dst:\n return d + 1\n if v not in visited:\n visited.add(v)\n q.append((v, d + 1))\n return -1\n```"}]} {"category": "loop_fixing_bug_repair", "lang": "python", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert algorithm & loop-termination engineer."}, {"role": "user", "content": "Fix the cycle-induced infinite BFS loop on a directed graph with up to 60 nodes when computing shortest distance from `src` to `dst`."}, {"role": "assistant", "content": "Mark nodes in `visited` **at enqueue time** (not dequeue time) so cycles never re-enqueue visited vertices and queue size stays $O(V)$:\n\n```python\nfrom collections import deque\n\ndef bfs_shortest_path(adj: dict[int, list[int]], src: int, dst: int) -> int:\n if src == dst:\n return 0\n visited = {src}\n q = deque([(src, 0)])\n while q:\n u, d = q.popleft()\n for v in adj.get(u, ()):\n if v == dst:\n return d + 1\n if v not in visited:\n visited.add(v)\n q.append((v, d + 1))\n return -1\n```"}]} {"category": "loop_fixing_bug_repair", "lang": "python", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert algorithm & loop-termination engineer."}, {"role": "user", "content": "Fix the cycle-induced infinite BFS loop on a directed graph with up to 65 nodes when computing shortest distance from `src` to `dst`."}, {"role": "assistant", "content": "Mark nodes in `visited` **at enqueue time** (not dequeue time) so cycles never re-enqueue visited vertices and queue size stays $O(V)$:\n\n```python\nfrom collections import deque\n\ndef bfs_shortest_path(adj: dict[int, list[int]], src: int, dst: int) -> int:\n if src == dst:\n return 0\n visited = {src}\n q = deque([(src, 0)])\n while q:\n u, d = q.popleft()\n for v in adj.get(u, ()):\n if v == dst:\n return d + 1\n if v not in visited:\n visited.add(v)\n q.append((v, d + 1))\n return -1\n```"}]} {"category": "loop_fixing_bug_repair", "lang": "python", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert algorithm & loop-termination engineer."}, {"role": "user", "content": "Fix the cycle-induced infinite BFS loop on a directed graph with up to 70 nodes when computing shortest distance from `src` to `dst`."}, {"role": "assistant", "content": "Mark nodes in `visited` **at enqueue time** (not dequeue time) so cycles never re-enqueue visited vertices and queue size stays $O(V)$:\n\n```python\nfrom collections import deque\n\ndef bfs_shortest_path(adj: dict[int, list[int]], src: int, dst: int) -> int:\n if src == dst:\n return 0\n visited = {src}\n q = deque([(src, 0)])\n while q:\n u, d = q.popleft()\n for v in adj.get(u, ()):\n if v == dst:\n return d + 1\n if v not in visited:\n visited.add(v)\n q.append((v, d + 1))\n return -1\n```"}]} {"category": "loop_fixing_bug_repair", "lang": "python", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert algorithm & loop-termination engineer."}, {"role": "user", "content": "Fix the cycle-induced infinite BFS loop on a directed graph with up to 75 nodes when computing shortest distance from `src` to `dst`."}, {"role": "assistant", "content": "Mark nodes in `visited` **at enqueue time** (not dequeue time) so cycles never re-enqueue visited vertices and queue size stays $O(V)$:\n\n```python\nfrom collections import deque\n\ndef bfs_shortest_path(adj: dict[int, list[int]], src: int, dst: int) -> int:\n if src == dst:\n return 0\n visited = {src}\n q = deque([(src, 0)])\n while q:\n u, d = q.popleft()\n for v in adj.get(u, ()):\n if v == dst:\n return d + 1\n if v not in visited:\n visited.add(v)\n q.append((v, d + 1))\n return -1\n```"}]} {"category": "loop_fixing_bug_repair", "lang": "python", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert algorithm & loop-termination engineer."}, {"role": "user", "content": "Fix the cycle-induced infinite BFS loop on a directed graph with up to 80 nodes when computing shortest distance from `src` to `dst`."}, {"role": "assistant", "content": "Mark nodes in `visited` **at enqueue time** (not dequeue time) so cycles never re-enqueue visited vertices and queue size stays $O(V)$:\n\n```python\nfrom collections import deque\n\ndef bfs_shortest_path(adj: dict[int, list[int]], src: int, dst: int) -> int:\n if src == dst:\n return 0\n visited = {src}\n q = deque([(src, 0)])\n while q:\n u, d = q.popleft()\n for v in adj.get(u, ()):\n if v == dst:\n return d + 1\n if v not in visited:\n visited.add(v)\n q.append((v, d + 1))\n return -1\n```"}]} {"category": "loop_fixing_bug_repair", "lang": "python", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert algorithm & loop-termination engineer."}, {"role": "user", "content": "Fix the cycle-induced infinite BFS loop on a directed graph with up to 85 nodes when computing shortest distance from `src` to `dst`."}, {"role": "assistant", "content": "Mark nodes in `visited` **at enqueue time** (not dequeue time) so cycles never re-enqueue visited vertices and queue size stays $O(V)$:\n\n```python\nfrom collections import deque\n\ndef bfs_shortest_path(adj: dict[int, list[int]], src: int, dst: int) -> int:\n if src == dst:\n return 0\n visited = {src}\n q = deque([(src, 0)])\n while q:\n u, d = q.popleft()\n for v in adj.get(u, ()):\n if v == dst:\n return d + 1\n if v not in visited:\n visited.add(v)\n q.append((v, d + 1))\n return -1\n```"}]} {"category": "loop_fixing_bug_repair", "lang": "python", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert algorithm & loop-termination engineer."}, {"role": "user", "content": "Fix the cycle-induced infinite BFS loop on a directed graph with up to 90 nodes when computing shortest distance from `src` to `dst`."}, {"role": "assistant", "content": "Mark nodes in `visited` **at enqueue time** (not dequeue time) so cycles never re-enqueue visited vertices and queue size stays $O(V)$:\n\n```python\nfrom collections import deque\n\ndef bfs_shortest_path(adj: dict[int, list[int]], src: int, dst: int) -> int:\n if src == dst:\n return 0\n visited = {src}\n q = deque([(src, 0)])\n while q:\n u, d = q.popleft()\n for v in adj.get(u, ()):\n if v == dst:\n return d + 1\n if v not in visited:\n visited.add(v)\n q.append((v, d + 1))\n return -1\n```"}]} {"category": "loop_fixing_bug_repair", "lang": "python", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert algorithm & loop-termination engineer."}, {"role": "user", "content": "Fix the cycle-induced infinite BFS loop on a directed graph with up to 95 nodes when computing shortest distance from `src` to `dst`."}, {"role": "assistant", "content": "Mark nodes in `visited` **at enqueue time** (not dequeue time) so cycles never re-enqueue visited vertices and queue size stays $O(V)$:\n\n```python\nfrom collections import deque\n\ndef bfs_shortest_path(adj: dict[int, list[int]], src: int, dst: int) -> int:\n if src == dst:\n return 0\n visited = {src}\n q = deque([(src, 0)])\n while q:\n u, d = q.popleft()\n for v in adj.get(u, ()):\n if v == dst:\n return d + 1\n if v not in visited:\n visited.add(v)\n q.append((v, d + 1))\n return -1\n```"}]} {"category": "loop_fixing_bug_repair", "lang": "python", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert algorithm & loop-termination engineer."}, {"role": "user", "content": "Fix the cycle-induced infinite BFS loop on a directed graph with up to 100 nodes when computing shortest distance from `src` to `dst`."}, {"role": "assistant", "content": "Mark nodes in `visited` **at enqueue time** (not dequeue time) so cycles never re-enqueue visited vertices and queue size stays $O(V)$:\n\n```python\nfrom collections import deque\n\ndef bfs_shortest_path(adj: dict[int, list[int]], src: int, dst: int) -> int:\n if src == dst:\n return 0\n visited = {src}\n q = deque([(src, 0)])\n while q:\n u, d = q.popleft()\n for v in adj.get(u, ()):\n if v == dst:\n return d + 1\n if v not in visited:\n visited.add(v)\n q.append((v, d + 1))\n return -1\n```"}]} {"category": "loop_fixing_bug_repair", "lang": "python", "messages": [{"role": "system", "content": "You are Alpha-27B, an expert algorithm & loop-termination engineer."}, {"role": "user", "content": "Fix the cycle-induced infinite BFS loop on a directed graph with up to 105 nodes when computing shortest distance from `src` to `dst`."}, {"role": "assistant", "content": "Mark nodes in `visited` **at enqueue time** (not dequeue time) so cycles never re-enqueue visited vertices and queue size stays $O(V)$:\n\n```python\nfrom collections import deque\n\ndef bfs_shortest_path(adj: dict[int, list[int]], src: int, dst: int) -> int:\n if src == dst:\n return 0\n visited = {src}\n q = deque([(src, 0)])\n while q:\n u, d = q.popleft()\n for v in adj.get(u, ()):\n if v == dst:\n return d + 1\n if v not in visited:\n visited.add(v)\n q.append((v, d + 1))\n return -1\n```"}]}