Submission #1084778

#TimeUsernameProblemLanguageResultExecution timeMemory
1084778IzzyBosses (BOI16_bosses)C++14
Compilation error
0 ms0 KiB
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <limits>
#include <set>
using namespace std;

int n;
map<int, vector<int>> arr;

int test(int start) {
    vector<bool> visited(n, false);
    vector<vector<int>> levels;
    queue<int> q;
    
    q.push(start);
    visited[start] = true;
    levels.push_back({start});
    
    int salary = 0;
    int lvl = 0;
    
    while (!q.empty()) {
        int levelSize = q.size();
        salary += levelSize * (lvl + 1);
        
        for (int i = 0; i < levelSize; i++) {
            int current = q.front();
            q.pop();
            
            if (arr.find(current) != arr.end()) {
                for (int neighbor : arr[current]) {
                    if (!visited[neighbor]) {
                        visited[neighbor] = true;
                        q.push(neighbor);
                    }
                }
            }
        }
        
        lvl++;
    }

    // Check if all nodes were visited
    if (find(visited.begin(), visited.end(), false) != visited.end()) {
        return numeric_limits<int>::max(); // Use a large value to indicate not all nodes were visited
    }
    
    return salary;
}

int main() {
    int salary = numeric_limits<int>::max(); // Initialize to a large value
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        int len;
        cin >> len;
        vector<int> temp(len);
        for (int j = 0; j < len; j++) {
            cin >> temp[j];
            temp[j]--; // Adjust for 0-based index
        }
        for (int x : temp) {
            if (arr.find(x) == arr.end()) {
                arr[x] = {i};
            } else {
                arr[x].push_back(i);
            }
        }
    }
    
    for (const auto& [key, _] : arr) {
        salary = min(salary, test(key));
    }
    
    cout << salary;
}

Compilation message (stderr)

bosses.cpp: In function 'int test(int)':
bosses.cpp:46:51: error: no matching function for call to 'find(std::vector<bool>::iterator, std::vector<bool>::iterator, bool)'
   46 |     if (find(visited.begin(), visited.end(), false) != visited.end()) {
      |                                                   ^
In file included from /usr/include/c++/10/bits/locale_facets.h:48,
                 from /usr/include/c++/10/bits/basic_ios.h:37,
                 from /usr/include/c++/10/ios:44,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from bosses.cpp:1:
/usr/include/c++/10/bits/streambuf_iterator.h:422:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(std::istreambuf_iterator<_CharT>, std::istreambuf_iterator<_CharT>, const _CharT2&)'
  422 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/10/bits/streambuf_iterator.h:422:5: note:   template argument deduction/substitution failed:
bosses.cpp:46:51: note:   'std::_Bit_iterator' is not derived from 'std::istreambuf_iterator<_CharT>'
   46 |     if (find(visited.begin(), visited.end(), false) != visited.end()) {
      |                                                   ^
bosses.cpp: In function 'int main()':
bosses.cpp:74:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   74 |     for (const auto& [key, _] : arr) {
      |                      ^