| Task: | Connect cities |
| Sender: | Isak |
| Submission time: | 2025-09-07 23:19:13 +0300 |
| Language: | C++ (C++20) |
| Status: | COMPILE ERROR |
Compiler report
In file included from /usr/include/c++/11/bits/stl_tree.h:65,
from /usr/include/c++/11/set:60,
from input/code.cpp:1:
/usr/include/c++/11/bits/stl_function.h: In instantiation of 'constexpr bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = std::unordered_set<unsigned int>]':
/usr/include/c++/11/bits/stl_tree.h:2071:35: required from 'std::pair<std::_Rb_tree_node_base*, std::_Rb_tree_node_base*> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_get_insert_unique_pos(const key_type&) [with _Key = std::unordered_set<unsigned int>; _Val = std::unordered_set<unsigned int>; _KeyOfValue = std::_Identity<std::unordered_set<unsigned int> >; _Compare = std::less<std::unordered_set<unsigned int> >; _Alloc = std::allocator<std::unordered_set<unsigned int> >; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::key_type = std::unordered_set<unsigned int>]'
/usr/include/c++/11/bits/stl_tree.h:2124:4: required from 'std::pa...Code
#include <set>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <unordered_set>
std::unordered_set<uint32_t> find_in_set(std::set<std::unordered_set<uint32_t>> s, uint32_t to_find){
auto r= s.begin();
for (; r != s.end() && ! (*r).contains(to_find); r++);
return *r;
}
int main() {
uint32_t n = 0;
uint32_t m = 1;
if (scanf("%d %d", &n, &m) == 0)
return EXIT_FAILURE;
std::set<std::unordered_set<uint32_t>> s;
for (uint32_t i = 0; i < n; i++){
s.insert({i});
}
// main algo
uint32_t x, y;
std::unordered_set<uint32_t> sx, sy;
sx = *s.begin();
for(uint32_t i = 0; i < m; i++){
if (scanf("%d %d", &x, &y) == 0)
return EXIT_FAILURE;
sx = find_in_set(s, x);
if (! sx.contains(y)){
sy = find_in_set(s, y);
s.erase(sy);
sx.merge(sy);
}
}
printf("%ld\n", s.size());
if (s.size() > 1){
s.erase(sx);
for (auto r = s.begin(); r != s.end(); r++){
printf("%d %d", *sx.begin(), *sy.begin());
}
}
return EXIT_SUCCESS;
}
