Submission #984951

# Submission time Handle Problem Language Result Execution time Memory
984951 2024-05-17T08:39:47 Z 54skyxenon Crocodile's Underground City (IOI11_crocodile) C++17
Compilation error
0 ms 0 KB
// https://oj.uz/problem/view/IOI11_crocodile

/** Needed for linking!!! */
#include "crocodile.h"

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define INF (ll)1e18

vector<map<int, int>> graph;
vector<bool> is_exit;
vector<set<int>> visited;

ll dfs(int curr) {
    if (is_exit[curr]) {
        return 0;
    }

    vector<ll> distances;
    for (auto [nei, weight] : graph[curr]) {
        if (!visited[nei].count(curr)) {
            visited[nei].insert(curr);
            distances.push_back(weight + dfs(nei));
        }
    }

    sort(distances.begin(), distances.end());

    if (distances.size() < 2) {
        // return INF;
        throw runtime_error("Got into a cycle!");
    }

    return distances[1];
}

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
    graph.resize(N);
    is_exit.resize(N);
    visited.resize(N);

    for (int i = 0; i < M; i++) {
        graph[R[i][0]][R[i][1]] = graph[R[i][1]][R[i][0]] = L[i];
    }

    for (int i = 0; i < K; i++) {
        is_exit[P[i]] = true;
    }
        
    visited[0] = true;
    return dfs(0);

    // try {
    // }
    // catch (...) {
    //     vector<int> direct_escapes;
    //     for (auto [nei, dist] : graph[0]) {
    //         if (is_exit[nei]) {
    //             direct_escapes.push_back(dist);
    //         }
    //     }
    //     assert(direct_escapes.size() > 1);
    //     sort(direct_escapes.begin(), direct_escapes.end());
    //     return direct_escapes[1];
    //     return *min_element(direct_escapes.begin(), direct_escapes.end());
    // }
}

Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:52:18: error: no match for 'operator=' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::set<int> >, std::set<int> >::value_type' {aka 'std::set<int>'} and 'bool')
   52 |     visited[0] = true;
      |                  ^~~~
In file included from /usr/include/c++/10/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from crocodile.cpp:6:
/usr/include/c++/10/bits/stl_set.h:298:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>& std::set<_Key, _Compare, _Alloc>::operator=(const std::set<_Key, _Compare, _Alloc>&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>]'
  298 |       operator=(const set&) = default;
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_set.h:298:17: note:   no known conversion for argument 1 from 'bool' to 'const std::set<int>&'
  298 |       operator=(const set&) = default;
      |                 ^~~~~~~~~~
/usr/include/c++/10/bits/stl_set.h:302:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>& std::set<_Key, _Compare, _Alloc>::operator=(std::set<_Key, _Compare, _Alloc>&&) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>]'
  302 |       operator=(set&&) = default;
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_set.h:302:17: note:   no known conversion for argument 1 from 'bool' to 'std::set<int>&&'
  302 |       operator=(set&&) = default;
      |                 ^~~~~
/usr/include/c++/10/bits/stl_set.h:316:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>& std::set<_Key, _Compare, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Key = int; _Compare = std::less<int>; _Alloc = std::allocator<int>]'
  316 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_set.h:316:46: note:   no known conversion for argument 1 from 'bool' to 'std::initializer_list<int>'
  316 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~