#include <vector>#include <map>classGraphNode{public:intval;std::vector<GraphNode*>adj_nei;GraphNode(){val=0;adj_nei=std::vector<GraphNode*>();}GraphNode(int_val){val=_val;adj_nei=std::vector<GraphNode*>();}GraphNode(int_val,std::vector<GraphNode*>_adj_nei){val=_val;adj_nei=_adj_nei;}};classGraphNodeDeepCopy{private:std::map<GraphNode*,GraphNode*>v;public:GraphNode*dcGraph(GraphNode*gn){// Handle null input gracefullyif(gn==nullptr){returnnullptr;}if(v.find(gn)!=v.end()){returnv[gn];}// Create a new node. Note: We don't need to initialize adj_nei here.GraphNode*dcGraphNode=newGraphNode(gn->val);v[gn]=dcGraphNode;// Recursively copy the neighborsfor(GraphNode*nei:gn->adj_nei){dcGraphNode->adj_nei.push_back(dcGraph(nei));}returndcGraphNode;}};
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2024-12-05。"],[],[]]