-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1059.cpp
More file actions
25 lines (25 loc) · 720 Bytes
/
1059.cpp
File metadata and controls
25 lines (25 loc) · 720 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
class Solution {
public:
bool leadsToDestination(int n, vector<vector<int>>& edges, int source, int destination) {
vector<vector<int>> graph(n);
vector<int> indegree(n,0);
for(auto& edge: edges){
graph[edge[0]].push_back(edge[1]);
indegree[edge[1]]++;
}
queue<int> q;
q.push(source);
while(!q.empty()){
int u = q.front();q.pop();
if(graph[u].empty() && u!=destination)
return false;
for(int v: graph[u]){
if(indegree[v]<0)
return false;
indegree[v]--;
q.push(v);
}
}
return true;
}
};