邻接表¶
vecotr<vector<int>> buildGraph(int numCourses,vecotr<vecotr<int>>& prerequisites)
{
//定义节点数量
vecotr<vector<int>> graph(numCourses);
//每个节点设置可变数组存储目标点,视作边
for(int i=0;i<numCourses;i++)
{
graph[i] = new vector<int>();
}
//赋值
for(auto& edge: prerequisites)
{
int from = edge[1],to = edge[0];
graph[from].push_back(to);
}
return graph;
}