fork download
  1. #include <iostream>
  2. #include <unordered_set>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9. vector<pair<int, int> > prerequisites;
  10. prerequisites.emplace_back(0,1);
  11. prerequisites.emplace_back(2,0);
  12.  
  13. int n = 3;
  14. vector<pair<int, unordered_set<int>>> graph(n); // NO MORE DEFAULT RVALUE
  15. // We have to find our leaves:
  16. bool leaf[n];
  17. for(int i = 0; i < n; i++){
  18. leaf[i] = true;
  19. }
  20.  
  21. for(auto p : prerequisites){
  22. graph[p.first].first++;
  23. graph[p.first].second.insert(0);
  24. leaf[p.second] = false;
  25. }
  26.  
  27. vector<int> leaves;
  28. for(int i = 0; i < n; i++){
  29. if(leaf[i])
  30. leaves.push_back(i); // This causes a segfault if I don't change it.
  31. }
  32. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
Standard output is empty