#4670
gcd_tree
RAU-Gigel și Vlad sunt prieteni buni și le place tot timpul să se provoace unul pe altul. De data aceasta, RAU-Gigel a inventat o problemă interesantă de matematică.
Acesta are un arbore secret cu N
noduri (numerotate de la 1
la N
), în care fiecare nod are asociată o valoare (pe lângă numărul său de ordine din arbore), care este un număr natural și ii spune lui Vlad informații despre unele drumuri din acest arbore. O informație are forma x, y, val
și reprezintă faptul că lanțul din arbore de la nodul x
la nodul y
are cel mai mare divizor comun al valorilor asociate nodurilor acestuia egal cu val
, unde val
este un număr natural nenul.
Vlad știe că RAU-Gigel minte câteodată și s-ar putea ca unele dintre restricțiile date să fie eronate, astfel că vrea să afle întâi folosind informațiile ce le are la îndemână dacă ar putea exista un arbore care să respecte toate restricțiile date de prietenul său.
Pentru că știe ce programator iscusit ești, Vlad ți-ar fi foarte recunoscător daca l-ai putea ajuta cu această problemă prin a scrie un program care să o rezolve cât mai eficient.
RAU-Coder 2024
Problema | gcd_tree | Operații I/O |
![]() gcd_tree.in /gcd_tree.out
|
---|---|---|---|
Limita timp | 2 secunde | Limita memorie |
Total: 256 MB
/
Stivă 64 MB
|
Id soluție | #55818768 | Utilizator | |
Fișier | gcd_tree.cpp | Dimensiune | 2.27 KB |
Data încărcării | 27 Ianuarie 2025, 18:04 | Scor / rezultat | Eroare de compilare |
gcd_tree.cpp: In member function 'int DSU::find(int)': gcd_tree.cpp:23:22: error: 'gcd' is not a member of 'std' gcd[x] = std::gcd(gcd[x], gcd[parent[x]]); ^ gcd_tree.cpp: In member function 'void DSU::union_sets(int, int, int)': gcd_tree.cpp:36:26: error: 'gcd' is not a member of 'std' gcd[rootY] = std::gcd(gcd[x], gcd[y]); ^ gcd_tree.cpp: In function 'int main()': gcd_tree.cpp:73:55: error: 'make_tuple' was not declared in this scope constraints.push_back(make_tuple(x, y, val)); ^ gcd_tree.cpp:81:26: error: 'tie' was not declared in this scope tie(x, y, val) = constraint; ^ In file included from /usr/include/c++/4.8/bits/stl_algobase.h:67: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 gcd_tree.cpp:1: /usr/include/c++/4.8/bits/stl_iterator.h: In instantiation of '__gnu_cxx::__normal_iterator<_Iterator, _Container>& __gnu_cxx::__normal_iterator<_Iterator, _Container>::operator++() [with _Iterator = std::tuple<int, int, int>*; _Container = std::vector<std::tuple<int, int, int> >]': gcd_tree.cpp:79:33: required from here /usr/include/c++/4.8/bits/stl_iterator.h:748:2: error: cannot increment a pointer to incomplete type 'std::tuple<int, int, int>' ++_M_current; ^ In file included from /usr/include/c++/4.8/vector:64:0, from gcd_tree.cpp:2: /usr/include/c++/4.8/bits/stl_vector.h: In instantiation of 'std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >]': /usr/include/c++/4.8/bits/stl_vector.h:270:23: required from 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const allocator_type&) [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >; std::vector<_Tp, _Alloc>::size_type = unsigned int; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<std::tuple<int, int, int> >]' gcd_tree.cpp:69:51: required from here /usr/include/c++/4.8/bits/stl_vector.h:161:9: error: invalid use of incomplete type 'class std::tuple<int, int, int>' - this->_M_impl._M_start); } ^ In file included from /usr/include/c++/4.8/bits/stl_algobase.h:64: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 gcd_tree.cpp:1: /usr/include/c++/4.8/bits/stl_pair.h:83:11: error: declaration of 'class std::tuple<int, int, int>' class tuple; ^ In file included from /usr/include/c++/4.8/vector:64:0, from gcd_tree.cpp:2: /usr/include/c++/4.8/bits/stl_vector.h: In instantiation of 'void std::_Vector_base<_Tp, _Alloc>::_M_create_storage(std::size_t) [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >; std::size_t = unsigned int]': /usr/include/c++/4.8/bits/stl_vector.h:136:30: required from 'std::_Vector_base<_Tp, _Alloc>::_Vector_base(std::size_t, const allocator_type&) [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >; std::size_t = unsigned int; std::_Vector_base<_Tp, _Alloc>::allocator_type = std::allocator<std::tuple<int, int, int> >]' /usr/include/c++/4.8/bits/stl_vector.h:270:23: required from 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const allocator_type&) [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >; std::vector<_Tp, _Alloc>::size_type = unsigned int; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<std::tuple<int, int, int> >]' gcd_tree.cpp:69:51: required from here /usr/include/c++/4.8/bits/stl_vector.h:183:59: error: invalid use of incomplete type 'class std::tuple<int, int, int>' this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n; ^ In file included from /usr/include/c++/4.8/bits/stl_algobase.h:64: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 gcd_tree.cpp:1: /usr/include/c++/4.8/bits/stl_pair.h:83:11: error: declaration of 'class std::tuple<int, int, int>' class tuple; ^ In file included from /usr/include/c++/4.8/vector:62:0, from gcd_tree.cpp:2: /usr/include/c++/4.8/bits/stl_construct.h: In instantiation of 'void std::_Destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = std::tuple<int, int, int>*]': /usr/include/c++/4.8/bits/stl_construct.h:151:31: required from 'void std::_Destroy(_ForwardIterator, _ForwardIterator, std::allocator<_T2>&) [with _ForwardIterator = std::tuple<int, int, int>*; _Tp = std::tuple<int, int, int>]' /usr/include/c++/4.8/bits/stl_vector.h:416:30: required from 'std::vector<_Tp, _Alloc>::~vector() [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >]' gcd_tree.cpp:69:51: required from here /usr/include/c++/4.8/bits/stl_construct.h:127:27: error: invalid use of incomplete type '_Value_type {aka class std::tuple<int, int, int>}' __destroy(__first, __last); ^ In file included from /usr/include/c++/4.8/bits/stl_algobase.h:64: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 gcd_tree.cpp:1: /usr/include/c++/4.8/bits/stl_pair.h:83:11: error: declaration of '_Value_type {aka class std::tuple<int, int, int>}' class tuple; ^ In file included from /usr/include/c++/4.8/vector:63:0, from gcd_tree.cpp:2: /usr/include/c++/4.8/bits/stl_uninitialized.h: In instantiation of 'void std::__uninitialized_default_n(_ForwardIterator, _Size) [with _ForwardIterator = std::tuple<int, int, int>*; _Size = unsigned int]': /usr/include/c++/4.8/bits/stl_uninitialized.h:605:50: required from 'void std::__uninitialized_default_n_a(_ForwardIterator, _Size, std::allocator<_Tp>&) [with _ForwardIterator = std::tuple<int, int, int>*; _Size = unsigned int; _Tp = std::tuple<int, int, int>]' /usr/include/c++/4.8/bits/stl_vector.h:1225:28: required from 'void std::vector<_Tp, _Alloc>::_M_default_initialize(std::vector<_Tp, _Alloc>::size_type) [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >; std::vector<_Tp, _Alloc>::size_type = unsigned int]' /usr/include/c++/4.8/bits/stl_vector.h:271:34: required from 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const allocator_type&) [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >; std::vector<_Tp, _Alloc>::size_type = unsigned int; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<std::tuple<int, int, int> >]' gcd_tree.cpp:69:51: required from here /usr/include/c++/4.8/bits/stl_uninitialized.h:544:33: error: invalid use of incomplete type '_ValueType {aka class std::tuple<int, int, int>}' __uninit_default_n(__first, __n); ^ In file included from /usr/include/c++/4.8/bits/stl_algobase.h:64: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 gcd_tree.cpp:1: /usr/include/c++/4.8/bits/stl_pair.h:83:11: error: declaration of '_ValueType {aka class std::tuple<int, int, int>}' class tuple; ^ In file included from /usr/include/i386-linux-gnu/c++/4.8/bits/c++allocator.h:33:0, from /usr/include/c++/4.8/bits/allocator.h:46, from /usr/include/c++/4.8/string:41, 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 gcd_tree.cpp:1: /usr/include/c++/4.8/ext/new_allocator.h: In instantiation of '_Tp* __gnu_cxx::new_allocator<_Tp>::allocate(__gnu_cxx::new_allocator<_Tp>::size_type, const void*) [with _Tp = std::tuple<int, int, int>; __gnu_cxx::new_allocator<_Tp>::pointer = std::tuple<int, int, int>*; __gnu_cxx::new_allocator<_Tp>::size_type = unsigned int]': /usr/include/c++/4.8/bits/stl_vector.h:168:25: required from 'std::_Vector_base<_Tp, _Alloc>::pointer std::_Vector_base<_Tp, _Alloc>::_M_allocate(std::size_t) [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >; std::_Vector_base<_Tp, _Alloc>::pointer = std::tuple<int, int, int>*; std::size_t = unsigned int]' /usr/include/c++/4.8/bits/stl_vector.h:181:25: required from 'void std::_Vector_base<_Tp, _Alloc>::_M_create_storage(std::size_t) [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >; std::size_t = unsigned int]' /usr/include/c++/4.8/bits/stl_vector.h:136:30: required from 'std::_Vector_base<_Tp, _Alloc>::_Vector_base(std::size_t, const allocator_type&) [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >; std::size_t = unsigned int; std::_Vector_base<_Tp, _Alloc>::allocator_type = std::allocator<std::tuple<int, int, int> >]' /usr/include/c++/4.8/bits/stl_vector.h:270:23: required from 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const allocator_type&) [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >; std::vector<_Tp, _Alloc>::size_type = unsigned int; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<std::tuple<int, int, int> >]' gcd_tree.cpp:69:51: required from here /usr/include/c++/4.8/ext/new_allocator.h:104:54: error: invalid application of 'sizeof' to incomplete type 'std::tuple<int, int, int>' return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp))); ^ /usr/include/c++/4.8/ext/new_allocator.h: In instantiation of '__gnu_cxx::new_allocator<_Tp>::size_type __gnu_cxx::new_allocator<_Tp>::max_size() const [with _Tp = std::tuple<int, int, int>; __gnu_cxx::new_allocator<_Tp>::size_type = unsigned int]': /usr/include/c++/4.8/ext/new_allocator.h:101:10: required from '_Tp* __gnu_cxx::new_allocator<_Tp>::allocate(__gnu_cxx::new_allocator<_Tp>::size_type, const void*) [with _Tp = std::tuple<int, int, int>; __gnu_cxx::new_allocator<_Tp>::pointer = std::tuple<int, int, int>*; __gnu_cxx::new_allocator<_Tp>::size_type = unsigned int]' /usr/include/c++/4.8/bits/stl_vector.h:168:25: required from 'std::_Vector_base<_Tp, _Alloc>::pointer std::_Vector_base<_Tp, _Alloc>::_M_allocate(std::size_t) [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >; std::_Vector_base<_Tp, _Alloc>::pointer = std::tuple<int, int, int>*; std::size_t = unsigned int]' /usr/include/c++/4.8/bits/stl_vector.h:181:25: required from 'void std::_Vector_base<_Tp, _Alloc>::_M_create_storage(std::size_t) [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >; std::size_t = unsigned int]' /usr/include/c++/4.8/bits/stl_vector.h:136:30: required from 'std::_Vector_base<_Tp, _Alloc>::_Vector_base(std::size_t, const allocator_type&) [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >; std::size_t = unsigned int; std::_Vector_base<_Tp, _Alloc>::allocator_type = std::allocator<std::tuple<int, int, int> >]' /usr/include/c++/4.8/bits/stl_vector.h:270:23: required from 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const allocator_type&) [with _Tp = std::tuple<int, int, int>; _Alloc = std::allocator<std::tuple<int, int, int> >; std::vector<_Tp, _Alloc>::size_type = unsigned int; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<std::tuple<int, int, int> >]' gcd_tree.cpp:69:51: required from here /usr/include/c++/4.8/ext/new_allocator.h:114:35: error: invalid application of 'sizeof' to incomplete type 'std::tuple<int, int, int>' { return size_t(-1) / sizeof(_Tp); } ^
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema gcd_tree 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ă.