{"ScriptPreparationCode":null,"TestCases":[{"Name":"array","Code":"const graph = Array.from({ length: 101 }, () =\u003E []);\r\n\r\nfor (let i = 0; i \u003C 100; i\u002B\u002B) {\r\n const a=Math.floor(Math.random() * 100) \u002B 1\r\n graph[i].push(a);\r\n graph[a].push(i)\r\n}\r\nfor (let i = 0; i \u003C 100; i\u002B\u002B) {\r\n const a=Math.floor(Math.random() * 100) \u002B 1\r\n const b=Math.floor(Math.random() * 100) \u002B 1\r\n graph[a].push(b)\r\n graph[b].push(a)\r\n}\r\nfunction dfs(i) {\r\n \r\n const stack = [i];\r\n const visited = Array.from({ length: 101 }, () =\u003E 0);\r\n visited[i] = 1;\r\n while (stack.length) {\r\n const target = stack.pop();\r\n \r\n for (let i = 0; i \u003C graph[target].length; i\u002B\u002B) {\r\n if (!visited[graph[target][i]]) {\r\n stack.push(graph[target][i]);\r\n visited[graph[target][i]] = 1;\r\n }\r\n }\r\n }\r\n}\r\nfor (let i = 0; i \u003C100; i\u002B\u002B) {\r\n dfs(i);\r\n}","IsDeferred":false},{"Name":"map","Code":"class Graph {\r\n constructor() {\r\n this.list = new Map();\r\n }\r\n\r\n add(v1, v2) {\r\n if (!this.list.has(v1)) this.list.set(v1, []);\r\n if (!this.list.has(v2)) this.list.set(v2, []);\r\n this.list.get(v2).push(v1);\r\n this.list.get(v1).push(v2);\r\n }\r\n dfs(start) {\r\n const stack = [start];\r\n \r\n const visited = new Map();\r\n visited.set(start, true);\r\n while (stack.length) {\r\n const target = this.list.get(stack.pop());\r\n for (let i = 0; i \u003C target.length; i\u002B\u002B) {\r\n if (!visited.has(target[i])) {\r\n stack.push(target[i]);\r\n visited.set(target[i], true);\r\n \r\n }\r\n }\r\n }\r\n return \r\n }\r\n}\r\nconst graph = new Graph();\r\nfor (let i = 0; i \u003C 100; i\u002B\u002B) {\r\n graph.add(i, Math.floor(Math.random() * 100) \u002B 1);\r\n}\r\nfor (let i = 0; i \u003C 100; i\u002B\u002B) {\r\n graph.add(Math.floor(Math.random() * 100) \u002B 1, Math.floor(Math.random() * 100) \u002B 1);\r\n}\r\nfor (const [num, _] of graph.list) {\r\n graph.dfs(num);\r\n}\r\n","IsDeferred":false}]}