-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1462. Course Schedule IV
More file actions
33 lines (28 loc) · 858 Bytes
/
Copy path1462. Course Schedule IV
File metadata and controls
33 lines (28 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Solution {
public:
vector<int> g[101];
int possible[101][101],vis[101];
void dfs(int node,int p) {
possible[p][node] = 1;
vis[node] = 1;
for(int ch : g[node]) {
if(vis[ch] == 0) dfs(ch,p);
}
}
vector<bool> checkIfPrerequisite(int numCourses, vector<vector<int>>& prerequisites, vector<vector<int>>& queries) {
memset(possible,0,sizeof possible);
for(auto it : prerequisites) {
g[it[0]].push_back(it[1]);
}
for(int i = 0; i < numCourses; i++) {
memset(vis,0,sizeof vis);
dfs(i,i);
}
vector<bool> ans;
for(auto it : queries) {
if(possible[it[0]][it[1]]) ans.push_back(true);
else ans.push_back(false);
}
return ans;
}
};