fork(2) download
  1. #include <vector>
  2. #include <bitset>
  3. #include <iterator>
  4. #include <fstream>
  5. #include <sstream>
  6. #include <iostream>
  7. const int N=6;
  8. std::vector<std::bitset<N> > read_graph(const std::string& filepath)
  9. {
  10. std::vector<std::bitset<N> > bs(N);
  11. std::ifstream fp(filepath.c_str());
  12. for(std::string line; getline(std::cin, line); ) // using std::cin for this demo
  13. {
  14. if(line.size() > 1 && line[0] == 'a')
  15. {
  16. std::istringstream str(line.substr(1));
  17. int fi, si;
  18. str >> fi >> si;
  19. std::cout << "fi: " << fi << " si: " << si << '\n';
  20. bs[--fi][--si]= 1;
  21. }
  22. }
  23. return bs;
  24. }
  25. int main()
  26. {
  27. std::vector<std::bitset<N> > v = read_graph("sample.gr");
  28. copy(v.rbegin(), v.rend(), std::ostream_iterator<std::bitset<N> >(std::cout, "\n"));
  29. }
  30.  
Success #stdin #stdout 0s 2868KB
stdin
c 9th DIMACS Implementation Challenge: Shortest Paths
c http://w...content-available-to-author-only...1.it/~challenge9
c Sample graph file
c
p sp 6 8
c graph contains 6 nodes and 8 arcs
c node ids are numbers in 1..6
c
a 1 2 17
c arc from node 1 to node 2 of weight 17
c
a 1 3 10
a 2 4 2
a 3 5 0
a 4 3 0
a 4 6 3
a 5 2 0
a 5 6 20
stdout
fi: 1   si: 2
fi: 1   si: 3
fi: 2   si: 4
fi: 3   si: 5
fi: 4   si: 3
fi: 4   si: 6
fi: 5   si: 2
fi: 5   si: 6
000000
100010
100100
010000
001000
000110