#4950
Fie G un graf neorientat conex cu N noduri și M muchii. Nodurile sunt numerotate de la 1 la N iar muchiile au asociate costuri numere naturale date. Un graf parţial al lui G conex şi fără cicluri este denumit arbore parţial. Costul unui arbore parțial este suma costurilor muchiilor arborelui. Deoarece unele muchii pot avea aceelași cost, este posibil ca graful G să aibă mai mulți arbori parțiali de cost minim. Definim o muchie a grafului G ca fiind esențială dacă ea face parte din toți arborii parțiali de cost minim ai lui G. Scrieţi un program care, cunoscând graful, rezolvă următoarele două cerinţe:
1. determină costul unui arbore parțial de cost minim al lui G;
2. determină numărul de muchii esențiale ale grafului G.
OMI 2026, clasele 11-12
| Problema | esentiale | Operații I/O |
esentiale.in/esentiale.out
|
|---|---|---|---|
| Limita timp | 0.5 secunde | Limita memorie |
Total: 64 MB
/
Stivă 16 MB
|
| Id soluție | #63217907 | Utilizator | |
| Fișier | esentiale.cpp | Dimensiune | 1.04 KB |
| Data încărcării | 21 Februarie 2026, 18:12 | Scor/rezultat | Eroare de compilare |
esentiale.cpp: In function 'int main()': esentiale.cpp:38:37: error: parameter declared 'auto' sort(v.begin(),v.end(),[](auto &a,auto &b) { ^ esentiale.cpp:38:45: error: parameter declared 'auto' sort(v.begin(),v.end(),[](auto &a,auto &b) { ^ esentiale.cpp: In lambda function: esentiale.cpp:39:16: error: 'a' was not declared in this scope return a.c<b.c; ^ esentiale.cpp:39:20: error: 'b' was not declared in this scope return a.c<b.c; ^ esentiale.cpp: In function 'int main()': esentiale.cpp:41:9: warning: unused variable 'k' [-Wunused-variable] int k=0,smin=0; ^ In file included from /usr/include/c++/4.8/algorithm:62:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:64, from esentiale.cpp:1: /usr/include/c++/4.8/bits/stl_algo.h: In instantiation of 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<dd*, std::vector<dd> >; _Compare = main()::__lambda4]': /usr/include/c++/4.8/bits/stl_algo.h:2226:70: required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<dd*, std::vector<dd> >; _Compare = main()::__lambda4]' /usr/include/c++/4.8/bits/stl_algo.h:5500:55: required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<dd*, std::vector<dd> >; _Compare = main()::__lambda4]' esentiale.cpp:40:6: required from here /usr/include/c++/4.8/bits/stl_algo.h:2159:29: error: no match for call to '(main()::__lambda4) (dd&, dd&)' if (__comp(*__i, *__first)) ^ esentiale.cpp:38:29: note: candidates are: sort(v.begin(),v.end(),[](auto &a,auto &b) { ^ In file included from /usr/include/c++/4.8/algorithm:62:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:64, from esentiale.cpp:1: /usr/include/c++/4.8/bits/stl_algo.h:2159:29: note: void (*)() <conversion> if (__comp(*__i, *__first)) ^ /usr/include/c++/4.8/bits/stl_algo.h:2159:29: note: candidate expects 1 argument, 3 provided esentiale.cpp:38:46: note: main()::__lambda4 sort(v.begin(),v.end(),[](auto &a,auto &b) { ^ esentiale.cpp:38:46: note: candidate expects 0 arguments, 2 provided In file included from /usr/include/c++/4.8/algorithm:62:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:64, from esentiale.cpp:1: /usr/include/c++/4.8/bits/stl_algo.h: In instantiation of 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<dd*, std::vector<dd> >; _Compare = main()::__lambda4]': /usr/include/c++/4.8/bits/stl_algo.h:5349:59: required from 'void std::partial_sort(_RAIter, _RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<dd*, std::vector<dd> >; _Compare = main()::__lambda4]' /usr/include/c++/4.8/bits/stl_algo.h:2332:68: required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<dd*, std::vector<dd> >; _Size = int; _Compare = main()::__lambda4]' /usr/include/c++/4.8/bits/stl_algo.h:5499:44: required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<dd*, std::vector<dd> >; _Compare = main()::__lambda4]' esentiale.cpp:40:6: required from here /usr/include/c++/4.8/bits/stl_algo.h:1948:27: error: no match for call to '(main()::__lambda4) (dd&, dd&)' if (__comp(*__i, *__first)) ^ esentiale.cpp:38:29: note: candidates are: sort(v.begin(),v.end(),[](auto &a,auto &b) { ^ In file included from /usr/include/c++/4.8/algorithm:62:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:64, from esentiale.cpp:1: /usr/include/c++/4.8/bits/stl_algo.h:1948:27: note: void (*)() <conversion> if (__comp(*__i, *__first)) ^ /usr/include/c++/4.8/bits/stl_algo.h:1948:27: note: candidate expects 1 argument, 3 provided esentiale.cpp:38:46: note: main()::__lambda4 sort(v.begin(),v.end(),[](auto &a,auto &b) { ^ esentiale.cpp:38:46: note: candidate expects 0 arguments, 2 provided In file included from /usr/include/c++/4.8/algorithm:62:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:64, from esentiale.cpp:1: /usr/include/c++/4.8/bits/stl_algo.h: In instantiation of 'void std::__move_median_to_first(_Iterator, _Iterator, _Iterator, _Iterator, _Compare) [with _Iterator = __gnu_cxx::__normal_iterator<dd*, std::vector<dd> >; _Compare = main()::__lambda4]': /usr/include/c++/4.8/bits/stl_algo.h:2295:13: required from '_RandomAccessIterator std::__unguarded_partition_pivot(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<dd*, std::vector<dd> >; _Compare = main()::__lambda4]' /usr/include/c++/4.8/bits/stl_algo.h:2337:62: required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<dd*, std::vector<dd> >; _Size = int; _Compare = main()::__lambda4]' /usr/include/c++/4.8/bits/stl_algo.h:5499:44: required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<dd*, std::vector<dd> >; _Compare = main()::__lambda4]' esentiale.cpp:40:6: required from here /usr/include/c++/4.8/bits/stl_algo.h:114:28: error: no match for call to '(main()::__lambda4) (dd&, dd&)' if (__comp(*__a, *__b)) ^ esentiale.cpp:38:29: note: candidates are: sort(v.begin(),v.end(),[](auto &a,auto &b) { ^ In file included from /usr/include/c++/4.8/algorithm:62:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:64, from esentiale.cpp:1: /usr/include/c++/4.8/bits/stl_algo.h:114:28: note: void (*)() <conversion> if (__comp(*__a, *__b)) ^ /usr/include/c++/4.8/bits/stl_algo.h:114:28: note: candidate expects 1 argument, 3 provided esentiale.cpp:38:46: note: main()::__lambda4 sort(v.begin(),v.end(),[](auto &a,auto &b) { ^ esentiale.cpp:38:46: note: candidate expects 0 arguments, 2 provided In file included from /usr/include/c++/4.8/algorithm:62:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:64, from esentiale.cpp:1: /usr/include/c++/4.8/bits/stl_algo.h:116:25: error: no match for call to '(main()::__lambda4) (dd&, dd&)' if (__comp(*__b, *__c)) ^ esentiale.cpp:38:29: note: candidates are: sort(v.begin(),v.end(),[](auto &a,auto &b) { ^ In file included from /usr/include/c++/4.8/algorithm:62:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:64, from esentiale.cpp:1: /usr/include/c++/4.8/bits/stl_algo.h:116:25: note: void (*)() <conversion> if (__comp(*__b, *__c)) ^ /usr/include/c++/4.8/bits/stl_algo.h:116:25: note: candidate expects 1 argument, 3 provided esentiale.cpp:38:46: note: main()::__lambda4 sort(v.begin(),v.end(),[](auto &a,auto &b) { ^ esentiale.cpp:38:46: note: candidate expects 0 arguments, 2 provided In file included from /usr/include/c++/4.8/algorithm:62:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:64, from esentiale.cpp:1: /usr/include/c++/4.8/bits/stl_algo.h:118:30: error: no match for call to '(main()::__lambda4) (dd&, dd&)' else if (__comp(*__a, *__c)) ^ esentiale.cpp:38:29: note: candidates are: sort(v.begin(),v.end(),[](auto &a,auto &b) { ^ In file included from /usr/include/c++/4.8/algorithm:62:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:64, from esentiale.cpp:1: /usr/include/c++/4.8/bits/stl_algo.h:118:30: note: void (*)() <conversion> else if (__comp(*__a, *__c)) ^ /usr/include/c++/4.8/bits/stl_algo.h:118:30: note: candidate expects 1 argument, 3 provided esentiale.cpp:38:46: note: main()::__lambda4 sort(v.begin(),v.end(),[](auto &a,auto &b) { ^ esentiale.cpp:38:46: note: candidate expects 0 arguments, 2 provided In file included from /usr/include/c++/4.8/algorithm:62:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:64, from esentiale.cpp:1: /usr/include/c++/4.8/bits/stl_algo.h:123:33: error: no match for call to '(main()::__lambda4) (dd&, dd&)' else if (__comp(*__a, *__c)) ^ esentiale.cpp:38:29: note: candidates are: sort(v.begin(),v.end(),[](auto &a,auto &b) { ^ In file included from /usr/include/c++/4.8/algorithm:62:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:64, from esentiale.cpp:1: /usr/include/c++/4.8/bits/stl_algo.h:123:33: note: void (*)() <conversion> else if (__comp(*__a, *__c)) ^ /usr/include/c++/4.8/bits/stl_algo.h:123:33: note: candidate expects 1 argument, 3 provided esentiale.cpp:38:46: note: main()::__lambda4 sort(v.begin(),v.end(),[](auto &a,auto &b) { ^ esentiale.cpp:38:46: note: candidate expects 0 arguments, 2 provided In file included from /usr/include/c++/4.8/algorithm:62:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:64, from esentiale.cpp:1: /usr/include/c++/4.8/bits/stl_algo.h:125:33: error: no match for call to '(main()::__lambda4) (dd&, dd&)' else if (__comp(*__b, *__c)) ^ esentiale.cpp:38:29: note: candidates are: sort(v.begin(),v.end(),[](auto &a,auto &b) { ^ In file included from /usr/include/c++/4.8/algorithm:62:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:64, from esentiale.cpp:1: /usr/include/c++/4.8/bits/stl_algo.h:125:33: note: void (*)() <conversion> else if (__comp(*__b, *__c)) ^ /usr/include/c++/4.8/bits/stl_algo.h:125:33: note: candidate expects 1 argument, 3 provided esentiale.cpp:38:46: note: main()::__lambda4 sort(v.begin(),v.end(),[](auto &a,auto &b) { ^ esentiale.cpp:38:46: note: candidate expects 0 arguments, 2 provided In file included from /usr/include/c++/4.8/algorithm:62:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:64, from esentiale.cpp:1: /usr/include/c++/4.8/bits/stl_algo.h: In instantiation of '_RandomAccessIterator std::__unguarded_partition(_RandomAccessIterator, _RandomAccessIterator, const _Tp&, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<dd*, std::vector<dd> >; _Tp = dd; _Compare = main()::__lambda4]': /usr/include/c++/4.8/bits/stl_algo.h:2296:78: required from '_RandomAccessIterator std::__unguarded_partition_pivot(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<dd*, std::vector<dd> >; _Compare = main()::__lambda4]' /usr/include/c++/4.8/bits/stl_algo.h:2337:62: required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<dd*, std::vector<dd> >; _Size = int; _Compare = main()::__lambda4]' /usr/include/c++/4.8/bits/stl_algo.h:5499:44: required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<dd*, std::vector<dd> >; _Compare = main()::__lambda4]' esentiale.cpp:40:6: required from here /usr/include/c++/4.8/bits/stl_algo.h:2263:35: error: no match for call to '(main()::__lambda4) (dd&, const dd&)' while (__comp(*__first, __pivot)) ^ esentiale.cpp:38:29: note: candidates are: sort(v.begin(),v.end(),[](auto &a,auto &b) { ^ In file included from /usr/include/c++/4.8/algorithm:62:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:64, from esentiale.cpp:1: /usr/include/c++/4.8/bits/stl_algo.h:2263:35: note: void (*)() <conversion> while (__comp(*__first, __pivot)) ^ /usr/include/c++/4.8/bits/stl_algo.h:2263:35: note: candidate expects 1 argument, 3 provided esentiale.cpp:38:46: note: main()::__lambda4 sort(v.begin(),v.end(),[](auto &a,auto &b) { ^ esentiale.cpp:38:46: note: candidate expects 0 arguments, 2 provided In file included from /usr/include/c++/4.8/algorithm:62:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:64, from esentiale.cpp:1: /usr/include/c++/4.8/bits/stl_algo.h:2266:34: error: no match for call to '(main()::__lambda4) (const dd&, dd&)' while (__comp(__pivot, *__last)) ^ esentiale.cpp:38:29: note: candidates are: sort(v.begin(),v.end(),[](auto &a,auto &b) { ^ In file included from /usr/include/c++/4.8/algorithm:62:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:64, from esentiale.cpp:1: /usr/include/c++/4.8/bits/stl_algo.h:2266:34: note: void (*)() <conversion> while (__comp(__pivot, *__last)) ^ /usr/include/c++/4.8/bits/stl_algo.h:2266:34: note: candidate expects 1 argument, 3 provided esentiale.cpp:38:46: note: main()::__lambda4 sort(v.begin(),v.end(),[](auto &a,auto &b) { ^ esentiale.cpp:38:46: note: candidate expects 0 arguments, 2 provided In file included from /usr/include/c++/4.8/bits/stl_algo.h:61:0, from /usr/include/c++/4.8/algorithm:62, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:64, from esentiale.cpp:1: /usr/include/c++/4.8/bits/stl_heap.h: In instantiation of 'void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<dd*, std::vector<dd> >; _Distance = int; _Tp = dd; _Compare = main()::__lambda4]': /usr/include/c++/4.8/bits/stl_heap.h:448:15: required from 'void std::make_heap(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<dd*, std::vector<dd> >; _Compare = main()::__lambda4]' /usr/include/c++/4.8/bits/stl_algo.h:1946:47: required from 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<dd*, std::vector<dd> >; _Compare = main()::__lambda4]' /usr/include/c++/4.8/bits/stl_algo.h:5349:59: required from 'void std::partial_sort(_RAIter, _RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<dd*, std::vector<dd> >; _Compare = main()::__lambda4]' /usr/include/c++/4.8/bits/stl_algo.h:2332:68: required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<dd*, std::vector<dd> >; _Size = int; _Compare = main()::__lambda4]' /usr/include/c++/4.8/bits/stl_algo.h:5499:44: required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<dd*, std::vector<dd> >; _Compare = main()::__lambda4]' esentiale.cpp:40:6: required from here /usr/include/c++/4.8/bits/stl_heap.h:313:40: error: no match for call to '(main()::__lambda4) (dd&, dd&)' *(__first + (__secondChild - 1)))) ^ esentiale.cpp:38:29: note: candidates are: sort(v.begin(),v.end(),[](auto &a,auto &b) { ^ In file included from /usr/include/c++/4.8/bits/stl_algo.h:61:0, from /usr/include/c++/4.8/algorithm:62, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:64, from esentiale.cpp:1: /usr/include/c++/4.8/bits/stl_heap.h:313:40: note: void (*)() <conversion> *(__first + (__secondChild - 1)))) ^ /usr/include/c++/4.8/bits/stl_heap.h:313:40: note: candidate expects 1 argument, 3 provided esentiale.cpp:38:46: note: main()::__lambda4 sort(v.begin(),v.end(),[](auto &a,auto &b) { ^ esentiale.cpp:38:46: note: candidate expects 0 arguments, 2 provided In file included from /usr/include/c++/4.8/algorithm:62:0, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:64, from esentiale.cpp:1: /usr/include/c++/4.8/bits/stl_algo.h: At global scope: /usr/include/c++/4.8/bits/stl_algo.h:2110:5: error: 'void std::__unguarded_linear_insert(_RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<dd*, std::vector<dd> >; _Compare = main()::__lambda4]', declared using local type 'main()::__lambda4', is used but never defined [-fpermissive] __unguarded_linear_insert(_RandomAccessIterator __last, ^ In file included from /usr/include/c++/4.8/bits/stl_algo.h:61:0, from /usr/include/c++/4.8/algorithm:62, from /usr/include/i386-linux-gnu/c++/4.8/bits/stdc++.h:64, from esentiale.cpp:1: /usr/include/c++/4.8/bits/stl_heap.h:331:5: error: 'void std::__pop_heap(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<dd*, std::vector<dd> >; _Compare = main()::__lambda4]', declared using local type 'main()::__lambda4', is used but never defined [-fpermissive] __pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, ^ /usr/include/c++/4.8/bits/stl_heap.h:178:5: error: 'void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<dd*, std::vector<dd> >; _Distance = int; _Tp = dd; _Compare = main()::__lambda4]', declared using local type 'main()::__lambda4', is used but never defined [-fpermissive] __push_heap(_RandomAccessIterator __first, _Distance __holeIndex, ^
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema esentiale 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ă.