3311. Construct 2D Grid Matching Graph Layout Hard
1/**
2 * [3311] Construct 2D Grid Matching Graph Layout
3 *
4 * You are given a 2D integer array edges representing an undirected graph having n nodes, where edges[i] = [ui, vi] denotes an edge between nodes ui and vi.
5 * Construct a 2D grid that satisfies these conditions:
6 *
7 * The grid contains all nodes from 0 to n - 1 in its cells, with each node appearing exactly once.
8 * Two nodes should be in adjacent grid cells (horizontally or vertically) if and only if there is an edge between them in edges.
9 *
10 * It is guaranteed that edges can form a 2D grid that satisfies the conditions.
11 * Return a 2D integer array satisfying the conditions above. If there are multiple solutions, return any of them.
12 *
13 * <strong class="example">Example 1:
14 * <div class="example-block">
15 * Input: <span class="example-io">n = 4, edges = [[0,1],[0,2],[1,3],[2,3]]</span>
16 * Output: <span class="example-io">[[3,1],[2,0]]</span>
17 * Explanation:
18 * <img alt="" src="https://assets.leetcode.com/uploads/2024/08/11/screenshot-from-2024-08-11-14-07-59.png" style="width: 133px; height: 92px;" />
19 * </div>
20 * <strong class="example">Example 2:
21 * <div class="example-block">
22 * Input: <span class="example-io">n = 5, edges = [[0,1],[1,3],[2,3],[2,4]]</span>
23 * Output: <span class="example-io">[[4,2,3,1,0]]</span>
24 * Explanation:
25 * <img src="https://assets.leetcode.com/uploads/2024/08/11/screenshot-from-2024-08-11-14-06-02.png" style="width: 325px; height: 50px;" />
26 * </div>
27 * <strong class="example">Example 3:
28 * <div class="example-block">
29 * Input: <span class="example-io">n = 9, edges = [[0,1],[0,4],[0,5],[1,7],[2,3],[2,4],[2,5],[3,6],[4,6],[4,7],[6,8],[7,8]]</span>
30 * Output: <span class="example-io">[[8,6,3],[7,4,2],[1,0,5]]</span>
31 * Explanation:
32 * <img alt="" src="https://assets.leetcode.com/uploads/2024/08/11/screenshot-from-2024-08-11-14-06-38.png" style="width: 198px; height: 133px;" />
33 * </div>
34 *
35 * Constraints:
36 *
37 * 2 <= n <= 5 * 10^4
38 * 1 <= edges.length <= 10^5
39 * edges[i] = [ui, vi]
40 * 0 <= ui < vi < n
41 * All the edges are distinct.
42 * The input is generated such that edges can form a 2D grid that satisfies the conditions.
43 *
44 */
45pub struct Solution {}
46
47// problem: https://leetcode.com/problems/construct-2d-grid-matching-graph-layout/
48// discuss: https://leetcode.com/problems/construct-2d-grid-matching-graph-layout/discuss/?currentPage=1&orderBy=most_votes&query=
49
50// submission codes start here
51
52impl Solution {
53 pub fn construct_grid_layout(n: i32, edges: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
54 vec![]
55 }
56}
57
58// submission codes end
59
60#[cfg(test)]
61mod tests {
62 use super::*;
63
64 #[test]
65 fn test_3311() {
66 }
67}
68
Back
© 2025 bowen.ge All Rights Reserved.