模板¶
约 8 个字 10 行代码 预计阅读时间不到 1 分钟
建图¶
bool canFinish(int numCourses, vector<vector<int>>& prerequisites) {
vector<vector<int>> graph(numCourses);
vector<int> inDegree(numCourses, 0);
for (auto &course : prerequisites) {
int a = course[0], b = course[1];
graph[b].push_back(a);
inDegree[a]++;
}
}