#588
Dijkstra
Se dă un graf orientat ponderat – în care fiecare arc are asociat un cost, număr natural strict pozitiv, și un nod p
. Să se determine, folosind algoritmul lui Dijkstra, costul minim al drumului de la p
la fiecare nod al grafului.
Problema | Dijkstra | Operații I/O |
dijkstra.in /dijkstra.out
|
---|---|---|---|
Limita timp | 0.1 secunde | Limita memorie |
Total: 64 MB
/
Stivă 8 MB
|
Id soluție | #54405152 | Utilizator | |
Fișier | dijkstra.cpp | Dimensiune | 2.63 KB |
Data încărcării | 27 Noiembrie 2024, 18:18 | Scor / rezultat | Eroare de compilare |
dijkstra.cpp: In function 'void dijkstra(int)': dijkstra.cpp:21:67: error: wrong number of template arguments (0, should be 1) priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> pq; ^ In file included from /usr/include/c++/4.8/string:48:0, from /usr/include/c++/4.8/bits/locale_classes.h:40, from /usr/include/c++/4.8/bits/ios_base.h:41, from /usr/include/c++/4.8/ios:42, from /usr/include/c++/4.8/ostream:38, from /usr/include/c++/4.8/iostream:39, from dijkstra.cpp:1: /usr/include/c++/4.8/bits/stl_function.h:222:12: error: provided for 'template<class _Tp> struct std::greater' struct greater : public binary_function<_Tp, _Tp, bool> ^ dijkstra.cpp:21:68: error: template argument 3 is invalid priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> pq; ^ dijkstra.cpp:21:73: error: invalid type in declaration before ';' token priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> pq; ^ dijkstra.cpp:22:5: error: reference to 'distance' is ambiguous distance[source] = 0; ^ dijkstra.cpp:17:13: note: candidates are: std::vector<int> distance vector<int> distance; // Minimum distances ^ In file included from /usr/include/c++/4.8/bits/stl_algobase.h:66:0, from /usr/include/c++/4.8/bits/char_traits.h:39, from /usr/include/c++/4.8/ios:40, from /usr/include/c++/4.8/ostream:38, from /usr/include/c++/4.8/iostream:39, from dijkstra.cpp:1: /usr/include/c++/4.8/bits/stl_iterator_base_funcs.h:114:5: note: template<class _InputIterator> typename std::iterator_traits<_Iterator>::difference_type std::distance(_InputIterator, _InputIterator) distance(_InputIterator __first, _InputIterator __last) ^ dijkstra.cpp:23:8: error: request for member 'push' in 'pq', which is of non-class type 'int' pq.push({0, source}); // {distance, node} ^ dijkstra.cpp:25:16: error: request for member 'empty' in 'pq', which is of non-class type 'int' while (!pq.empty()) { ^ dijkstra.cpp:26:23: error: request for member 'top' in 'pq', which is of non-class type 'int' int dist = pq.top().first; ^ dijkstra.cpp:27:26: error: request for member 'top' in 'pq', which is of non-class type 'int' int current = pq.top().second; ^ dijkstra.cpp:28:12: error: request for member 'pop' in 'pq', which is of non-class type 'int' pq.pop(); ^ dijkstra.cpp:30:20: error: reference to 'distance' is ambiguous if (dist > distance[current]) continue; // Ignore outdated pairs in the priority queue ^ dijkstra.cpp:17:13: note: candidates are: std::vector<int> distance vector<int> distance; // Minimum distances ^ In file included from /usr/include/c++/4.8/bits/stl_algobase.h:66:0, from /usr/include/c++/4.8/bits/char_traits.h:39, from /usr/include/c++/4.8/ios:40, from /usr/include/c++/4.8/ostream:38, from /usr/include/c++/4.8/iostream:39, from dijkstra.cpp:1: /usr/include/c++/4.8/bits/stl_iterator_base_funcs.h:114:5: note: template<class _InputIterator> typename std::iterator_traits<_Iterator>::difference_type std::distance(_InputIterator, _InputIterator) distance(_InputIterator __first, _InputIterator __last) ^ dijkstra.cpp:38:17: error: reference to 'distance' is ambiguous if (distance[current] + weight < distance[next]) { ^ dijkstra.cpp:17:13: note: candidates are: std::vector<int> distance vector<int> distance; // Minimum distances ^ In file included from /usr/include/c++/4.8/bits/stl_algobase.h:66:0, from /usr/include/c++/4.8/bits/char_traits.h:39, from /usr/include/c++/4.8/ios:40, from /usr/include/c++/4.8/ostream:38, from /usr/include/c++/4.8/iostream:39, from dijkstra.cpp:1: /usr/include/c++/4.8/bits/stl_iterator_base_funcs.h:114:5: note: template<class _InputIterator> typename std::iterator_traits<_Iterator>::difference_type std::distance(_InputIterator, _InputIterator) distance(_InputIterator __first, _InputIterator __last) ^ dijkstra.cpp:38:46: error: reference to 'distance' is ambiguous if (distance[current] + weight < distance[next]) { ^ dijkstra.cpp:17:13: note: candidates are: std::vector<int> distance vector<int> distance; // Minimum distances ^ In file included from /usr/include/c++/4.8/bits/stl_algobase.h:66:0, from /usr/include/c++/4.8/bits/char_traits.h:39, from /usr/include/c++/4.8/ios:40, from /usr/include/c++/4.8/ostream:38, from /usr/include/c++/4.8/iostream:39, from dijkstra.cpp:1: /usr/include/c++/4.8/bits/stl_iterator_base_funcs.h:114:5: note: template<class _InputIterator> typename std::iterator_traits<_Iterator>::difference_type std::distance(_InputIterator, _InputIterator) distance(_InputIterator __first, _InputIterator __last) ^ dijkstra.cpp:39:80: error: reference to 'distance' is ambiguous cout << "Updating distance for Node " << next << ": Old = " << distance[next] ^ dijkstra.cpp:17:13: note: candidates are: std::vector<int> distance vector<int> distance; // Minimum distances ^ In file included from /usr/include/c++/4.8/bits/stl_algobase.h:66:0, from /usr/include/c++/4.8/bits/char_traits.h:39, from /usr/include/c++/4.8/ios:40, from /usr/include/c++/4.8/ostream:38, from /usr/include/c++/4.8/iostream:39, from dijkstra.cpp:1: /usr/include/c++/4.8/bits/stl_iterator_base_funcs.h:114:5: note: template<class _InputIterator> typename std::iterator_traits<_Iterator>::difference_type std::distance(_InputIterator, _InputIterator) distance(_InputIterator __first, _InputIterator __last) ^ dijkstra.cpp:40:39: error: reference to 'distance' is ambiguous << ", New = " << distance[current] + weight << endl; ^ dijkstra.cpp:17:13: note: candidates are: std::vector<int> distance vector<int> distance; // Minimum distances ^ In file included from /usr/include/c++/4.8/bits/stl_algobase.h:66:0, from /usr/include/c++/4.8/bits/char_traits.h:39, from /usr/include/c++/4.8/ios:40, from /usr/include/c++/4.8/ostream:38, from /usr/include/c++/4.8/iostream:39, from dijkstra.cpp:1: /usr/include/c++/4.8/bits/stl_iterator_base_funcs.h:114:5: note: template<class _InputIterator> typename std::iterator_traits<_Iterator>::difference_type std::distance(_InputIterator, _InputIterator) distance(_InputIterator __first, _InputIterator __last) ^ dijkstra.cpp:42:17: error: reference to 'distance' is ambiguous distance[next] = distance[current] + weight; ^ dijkstra.cpp:17:13: note: candidates are: std::vector<int> distance vector<int> distance; // Minimum distances ^ In file included from /usr/include/c++/4.8/bits/stl_algobase.h:66:0, from /usr/include/c++/4.8/bits/char_traits.h:39, from /usr/include/c++/4.8/ios:40, from /usr/include/c++/4.8/ostream:38, from /usr/include/c++/4.8/iostream:39, from dijkstra.cpp:1: /usr/include/c++/4.8/bits/stl_iterator_base_funcs.h:114:5: note: template<class _InputIterator> typename std::iterator_traits<_Iterator>::difference_type std::distance(_InputIterator, _InputIterator) distance(_InputIterator __first, _InputIterator __last) ^ dijkstra.cpp:42:34: error: reference to 'distance' is ambiguous distance[next] = distance[current] + weight; ^ dijkstra.cpp:17:13: note: candidates are: std::vector<int> distance vector<int> distance; // Minimum distances ^ In file included from /usr/include/c++/4.8/bits/stl_algobase.h:66:0, from /usr/include/c++/4.8/bits/char_traits.h:39, from /usr/include/c++/4.8/ios:40, from /usr/include/c++/4.8/ostream:38, from /usr/include/c++/4.8/iostream:39, from dijkstra.cpp:1: /usr/include/c++/4.8/bits/stl_iterator_base_funcs.h:114:5: note: template<class _InputIterator> typename std::iterator_traits<_Iterator>::difference_type std::distance(_InputIterator, _InputIterator) distance(_InputIterator __first, _InputIterator __last) ^ dijkstra.cpp:44:20: error: request for member 'push' in 'pq', which is of non-class type 'int' pq.push({distance[next], next}); ^ dijkstra.cpp:44:26: error: reference to 'distance' is ambiguous pq.push({distance[next], next}); ^ dijkstra.cpp:17:13: note: candidates are: std::vector<int> distance vector<int> distance; // Minimum distances ^ In file included from /usr/include/c++/4.8/bits/stl_algobase.h:66:0, from /usr/include/c++/4.8/bits/char_traits.h:39, from /usr/include/c++/4.8/ios:40, from /usr/include/c++/4.8/ostream:38, from /usr/include/c++/4.8/iostream:39, from dijkstra.cpp:1: /usr/include/c++/4.8/bits/stl_iterator_base_funcs.h:114:5: note: template<class _InputIterator> typename std::iterator_traits<_Iterator>::difference_type std::distance(_InputIterator, _InputIterator) distance(_InputIterator __first, _InputIterator __last) ^ dijkstra.cpp: In function 'int main()': dijkstra.cpp:63:5: error: reference to 'distance' is ambiguous distance.assign(n + 1, INF); ^ dijkstra.cpp:17:13: note: candidates are: std::vector<int> distance vector<int> distance; // Minimum distances ^ In file included from /usr/include/c++/4.8/bits/stl_algobase.h:66:0, from /usr/include/c++/4.8/bits/char_traits.h:39, from /usr/include/c++/4.8/ios:40, from /usr/include/c++/4.8/ostream:38, from /usr/include/c++/4.8/iostream:39, from dijkstra.cpp:1: /usr/include/c++/4.8/bits/stl_iterator_base_funcs.h:114:5: note: template<class _InputIterator> typename std::iterator_traits<_Iterator>::difference_type std::distance(_InputIterator, _InputIterator) distance(_InputIterator __first, _InputIterator __last) ^ dijkstra.cpp:83:18: error: reference to 'distance' is ambiguous << (distance[i] != INF ? distance[i] : -1) << endl; ^ dijkstra.cpp:17:13: note: candidates are: std::vector<int> distance vector<int> distance; // Minimum distances ^ In file included from /usr/include/c++/4.8/bits/stl_algobase.h:66:0, from /usr/include/c++/4.8/bits/char_traits.h:39, from /usr/include/c++/4.8/ios:40, from /usr/include/c++/4.8/ostream:38, from /usr/include/c++/4.8/iostream:39, from dijkstra.cpp:1: /usr/include/c++/4.8/bits/stl_iterator_base_funcs.h:114:5: note: template<class _InputIterator> typename std::iterator_traits<_Iterator>::difference_type std::distance(_InputIterator, _InputIterator) distance(_InputIterator __first, _InputIterator __last) ^ dijkstra.cpp:83:39: error: reference to 'distance' is ambiguous << (distance[i] != INF ? distance[i] : -1) << endl; ^ dijkstra.cpp:17:13: note: candidates are: std::vector<int> distance vector<int> distance; // Minimum distances ^ In file included from /usr/include/c++/4.8/bits/stl_algobase.h:66:0, from /usr/include/c++/4.8/bits/char_traits.h:39, from /usr/include/c++/4.8/ios:40, from /usr/include/c++/4.8/ostream:38, from /usr/include/c++/4.8/iostream:39, from dijkstra.cpp:1: /usr/include/c++/4.8/bits/stl_iterator_base_funcs.h:114:5: note: template<class _InputIterator> typename std::iterator_traits<_Iterator>::difference_type std::distance(_InputIterator, _InputIterator) distance(_InputIterator __first, _InputIterator __last) ^ dijkstra.cpp:85:18: error: reference to 'distance' is ambiguous fout << (distance[i] != INF ? distance[i] : -1) << " "; ^ dijkstra.cpp:17:13: note: candidates are: std::vector<int> distance vector<int> distance; // Minimum distances ^ In file included from /usr/include/c++/4.8/bits/stl_algobase.h:66:0, from /usr/include/c++/4.8/bits/char_traits.h:39, from /usr/include/c++/4.8/ios:40, from /usr/include/c++/4.8/ostream:38, from /usr/include/c++/4.8/iostream:39, from dijkstra.cpp:1: /usr/include/c++/4.8/bits/stl_iterator_base_funcs.h:114:5: note: template<class _InputIterator> typename std::iterator_traits<_Iterator>::difference_type std::distance(_InputIterator, _InputIterator) distance(_InputIterator __first, _InputIterator __last) ^ dijkstra.cpp:85:39: error: reference to 'distance' is ambiguous fout << (distance[i] != INF ? distance[i] : -1) << " "; ^ dijkstra.cpp:17:13: note: candidates are: std::vector<int> distance vector<int> distance; // Minimum distances ^ In file included from /usr/include/c++/4.8/bits/stl_algobase.h:66:0, from /usr/include/c++/4.8/bits/char_traits.h:39, from /usr/include/c++/4.8/ios:40, from /usr/include/c++/4.8/ostream:38, from /usr/include/c++/4.8/iostream:39, from dijkstra.cpp:1: /usr/include/c++/4.8/bits/stl_iterator_base_funcs.h:114:5: note: template<class _InputIterator> typename std::iterator_traits<_Iterator>::difference_type std::distance(_InputIterator, _InputIterator) distance(_InputIterator __first, _InputIterator __last) ^
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema Dijkstra face parte din prima categorie. Soluția propusă de tine va fi evaluată astfel:
Suma punctajelor acordate pe testele utilizate pentru verificare este 100. Astfel, soluția ta poate obține cel mult 100 de puncte, caz în care se poate considera corectă.