fork(2) download
  1. #include <iostream>
  2. #include <map>
  3. #include <vector>
  4. #include <string>
  5. #include <utility>
  6. #include <algorithm>
  7. #include <stack>
  8. #include <queue>
  9. #include <climits>
  10.  
  11. using namespace std;
  12.  
  13. #define ll long long
  14. #define pb push_back
  15. #define mp make_pair
  16.  
  17. vector<pair<int,int> > mygraph[100001];
  18. int dist[100001];
  19.  
  20. void shortestpath(int n, int s);
  21. class heapnode
  22. {
  23. public:
  24. int vertex;
  25. int key;
  26. };
  27.  
  28. bool compare( heapnode &a, heapnode &b )
  29. {
  30. if (a.key < b.key)
  31. return true;
  32. return false;
  33. }
  34.  
  35. int main (void)
  36. {
  37. int t,i,j;
  38. for ( i = 0; i < 100001; i++ )
  39. dist[i] = -1;
  40. int a,b,c;
  41. int foo,n,m,s,e;
  42. cin>>t;
  43. while (t != 0)
  44. {
  45. cin>>n>>m>>s>>e;
  46. foo = m;
  47. while (foo != 0)
  48. {
  49. cin>>a>>b>>c;
  50. mygraph[a].pb(mp(b,c));
  51. mygraph[b].pb(mp(a,c));
  52. foo--;
  53. }
  54. shortestpath(n,s);
  55. if (dist[e] == -1)
  56. cout<<"NONE\n";
  57. else
  58. cout<<dist[e]<<"\n";
  59. t--;
  60. }
  61. return 0;
  62. }
  63.  
  64. void shortestpath(int n, int s)
  65. {
  66. vector<heapnode> myvec;
  67. myvec.resize(n);
  68. int i,j,val,weight;
  69. for ( i = 1; i <= n; i++ )
  70. {
  71. myvec[i].vertex = i;
  72. myvec[i].key = INT_MAX;
  73. }
  74. myvec[s].key = 0;
  75. bool visited[n+1];
  76. for ( i = 1; i <= n; i++)
  77. visited[i] = false;
  78. make_heap(myvec.begin(),myvec.end(),compare);
  79. vector<int> processedver;
  80. while (processedver.size() != n)
  81. {
  82. heapnode obj = myvec.front();
  83. pop_heap(myvec.begin(),myvec.end());
  84. myvec.pop_back();
  85. processedver.pb(obj.vertex);
  86. dist[obj.vertex] = obj.key;
  87. int u = obj.vertex;
  88. visited[u] = true;
  89. auto it = mygraph[u].begin();
  90. while (it != mygraph[u].end())
  91. {
  92. for (int j = 1; j <= n; j++)
  93. {
  94. if (it->first == j)
  95. {
  96. val = j;
  97. weight = it->second;
  98. break;
  99. }
  100. }
  101. if (visited[val] != true && myvec[val].key > (dist[u]+weight))
  102. {
  103. myvec[val].key = dist[u]+weight;
  104. }
  105. make_heap(myvec.begin(),myvec.end(),compare);
  106. it++;
  107. }
  108. }
  109. }
  110.  
  111.  
  112.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
In file included from /usr/include/c++/5/bits/stl_algobase.h:71:0,
                 from /usr/include/c++/5/bits/char_traits.h:39,
                 from /usr/include/c++/5/ios:40,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/5/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_less_iter::operator()(_Iterator1, _Iterator2) const [with _Iterator1 = __gnu_cxx::__normal_iterator<heapnode*, std::vector<heapnode> >; _Iterator2 = __gnu_cxx::__normal_iterator<heapnode*, std::vector<heapnode> >]':
/usr/include/c++/5/bits/stl_heap.h:215:14:   required from 'void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<heapnode*, std::vector<heapnode> >; _Distance = int; _Tp = heapnode; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/5/bits/stl_heap.h:245:25:   required from 'void std::__pop_heap(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<heapnode*, std::vector<heapnode> >; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
/usr/include/c++/5/bits/stl_heap.h:279:19:   required from 'void std::pop_heap(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<heapnode*, std::vector<heapnode> >]'
prog.cpp:83:37:   required from here
/usr/include/c++/5/bits/predefined_ops.h:43:23: error: no match for 'operator<' (operand types are 'heapnode' and 'heapnode')
       { return *__it1 < *__it2; }
                       ^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/5/bits/char_traits.h:39,
                 from /usr/include/c++/5/ios:40,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:849:5: note: candidate: template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)
     operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
     ^
/usr/include/c++/5/bits/stl_iterator.h:849:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/5/bits/stl_algobase.h:71:0,
                 from /usr/include/c++/5/bits/char_traits.h:39,
                 from /usr/include/c++/5/ios:40,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/5/bits/predefined_ops.h:43:23: note:   'heapnode' is not derived from 'const __gnu_cxx::__normal_iterator<_IteratorL, _Container>'
       { return *__it1 < *__it2; }
                       ^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
                 from /usr/include/c++/5/bits/char_traits.h:39,
                 from /usr/include/c++/5/ios:40,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:856:5: note: candidate: template<class _Iterator, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)
     operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
     ^
/usr/include/c++/5/bits/stl_iterator.h:856:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/5/bits/stl_algobase.h:71:0,
                 from /usr/include/c++/5/bits/char_traits.h:39,
                 from /usr/include/c++/5/ios:40,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/5/bits/predefined_ops.h:43:23: note:   'heapnode' is not derived from 'const __gnu_cxx::__normal_iterator<_Iterator, _Container>'
       { return *__it1 < *__it2; }
                       ^
stdout
Standard output is empty