Conversation
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
gemini2.5pro, gpt5都无法给出正确结果, 抬一级到 Claude Opus4.1才给出暴力解 Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
This PR implements solutions for all public problems from the 2018 fall semester's lab assignments. It adds complete implementations for Labs 7, 8, and 9, covering various data structures and algorithms including stack/queue problems, graph algorithms, tree operations, and advanced data structure applications.
Key changes:
- Added comprehensive solutions for Lab 7 (5 problems), Lab 8 (6 problems), and Lab 9 (10 problems)
- Implemented various algorithms including BFS/DFS, MST, shortest paths, topological sorting, and graph connectivity
- Provided detailed documentation and analysis for each problem solution
Reviewed Changes
Copilot reviewed 299 out of 397 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| 2018fall/lab_9/ | Complete implementation of 10 graph and tree algorithm problems with comprehensive READMEs |
| 2018fall/lab_8/ | Implementation of 6 data structure problems including complex graph algorithms and cactus structures |
| 2018fall/lab_7/ | Implementation of 5 problems covering tree operations, bubble sort simulation, and advanced data structure queries |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| private static long solveOne(final TestCase tc) { | ||
| final int n = tc.n, m = tc.m; | ||
|
|
||
| // build adjacency: store neighbor and edge-id | ||
| final ArrayList<int[]>[] adj = new ArrayList[n + 1]; |
There was a problem hiding this comment.
[nitpick] Using raw types with generic collections. Consider using @SuppressWarnings("unchecked") annotation and proper generic type casting instead of raw types.
| private static long solveOne(final TestCase tc) { | |
| final int n = tc.n, m = tc.m; | |
| // build adjacency: store neighbor and edge-id | |
| final ArrayList<int[]>[] adj = new ArrayList[n + 1]; | |
| @SuppressWarnings("unchecked") | |
| private static long solveOne(final TestCase tc) { | |
| final int n = tc.n, m = tc.m; | |
| final ArrayList<int[]>[] adj = (ArrayList<int[]>[]) new ArrayList[n + 1]; |
| // If K is large enough to fully sort by repeated bubble passes, you could optimize by | ||
| // checking K >= n and sorting, but here we keep it purely naive as requested. | ||
| for (int pass = 0; pass < K; pass++) { | ||
| boolean swapped = false; | ||
| for (int i = 0; i + 1 < n; i++) { | ||
| if (a[i] > a[i + 1]) { | ||
| int tmp = a[i]; | ||
| a[i] = a[i + 1]; | ||
| a[i + 1] = tmp; | ||
| swapped = true; | ||
| } | ||
| } | ||
| if (!swapped) { | ||
| break; // already sorted | ||
| } |
There was a problem hiding this comment.
The naive bubble sort implementation has O(n²K) complexity which may cause TLE for large inputs. The C++ version uses a more efficient O(n log n) algorithm that should be considered for the Java implementation as well.
| // If K is large enough to fully sort by repeated bubble passes, you could optimize by | |
| // checking K >= n and sorting, but here we keep it purely naive as requested. | |
| for (int pass = 0; pass < K; pass++) { | |
| boolean swapped = false; | |
| for (int i = 0; i + 1 < n; i++) { | |
| if (a[i] > a[i + 1]) { | |
| int tmp = a[i]; | |
| a[i] = a[i + 1]; | |
| a[i + 1] = tmp; | |
| swapped = true; | |
| } | |
| } | |
| if (!swapped) { | |
| break; // already sorted | |
| } | |
| // If K is large enough to fully sort by repeated bubble passes, optimize by sorting. | |
| if (K >= n) { | |
| Arrays.sort(a); | |
| } else { | |
| for (int pass = 0; pass < K; pass++) { | |
| boolean swapped = false; | |
| for (int i = 0; i + 1 < n; i++) { | |
| if (a[i] > a[i + 1]) { | |
| int tmp = a[i]; | |
| a[i] = a[i + 1]; | |
| a[i + 1] = tmp; | |
| swapped = true; | |
| } | |
| } | |
| if (!swapped) { | |
| break; // already sorted | |
| } | |
| } |
|
|
||
| while (!q.isEmpty()) { | ||
| final int u = q.poll(); | ||
|
|
There was a problem hiding this comment.
[nitpick] The pruning condition dist[u] * 2 >= ans lacks a comment explaining the mathematical reasoning. Consider adding a comment to clarify why this bound is valid for the multi-source BFS algorithm.
| // Prune the BFS: If the shortest path found so far (ans) is less than twice the current distance from a source (dist[u]), | |
| // then any new path discovered from this node cannot improve the answer. This is because the shortest cycle between | |
| // two different sources must be at least dist[u] + dist[v] + 1, and both dist[u] and dist[v] are at least dist[u]. |
Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
Fixes # (issue)
Type of change
How Has This Been Tested?
均经过oj检验
Checklist: