Submission #764594

# Submission time Handle Problem Language Result Execution time Memory
764594 2023-06-23T16:13:44 Z raysh07 Swapping Cities (APIO20_swap) C++17
Compilation error
0 ms 0 KB
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;

struct edge{
    int u, v, w;
};
 
int n, m;
const int maxn = 1e5 + 69;
vector <pair<int, int>> adj[maxn];
int root[maxn], mn[maxn];
set <edge> path, ans;
edge e[2 * maxn]
int mp[maxn];

int find(int x) {
    if (x == root[x]) return x;
    return root[x] = find(root[x]);
}

bool comp(edge x, edge y){
    return x.w < y.w;
}

bool unite(int x, int y){
    x = find(x); y = find(y);
    if (x == y) return false;
    
    root[y] = x;
    return true;
}

edge get(int u, int v, int w){
    edge ok;
    ok.u = u;
    ok.v = v;
    ok.w = w;
    return ok;
}

void dfs(int u, int need, int par){
    if (need == u) ans = path;
    for (auto [v, w] : adj[u]){
        path.insert(get(u, v, w));
        path.insert(get(v, u, w));
        dfs(v, need, u);
        path.erase(get(u, v, w));
        path.erase(get(v, u, w));
    }
}
 
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
    n = N;
    m = M;
    
    for (int i = 0; i < m; i++){
        e[i].u = U[i]; e[i].v = V[i]; e[i].w = W[i];
    }
    
    for (int i = 0; i < n; i++){
        root[i] = i;
        mn[i] = 1e9 + 1;
    }
    
    sort(e, e + m, comp);
    for (auto x : e){
        if (unite(x.u, x.v)){
            adj[x.u].push_back({x.v, x.w});
            adj[x.v].push_back({x.u, x.w});
        } else {
            mn[x.u] = min(mn[x.u], x.w);
            mn[x.v] = min(mn[x.v], x.w);
        }
    }
}
 
int getMinimumFuelCapacity(int x, int y) {
    dfs(x, y, -1);
    for (int i = 0; i < n; i++) mp[i] = 0;
    int lol = 0;
    for (auto x : ans) {
        lol = max(lol, x.w);
        mp[x.u]++;
        mp[x.v]++;
    }
    int l1 = 1e9 + 1;
    
    for (int i = 0; i < m; i++){
        if (ans.find(e[i]) == ans.end()){
            if (mp[e[i].u] || mp[e[i].v]) l1 = min(l1, e[i].w);
        }
    }
    
    if (l1 > 1e9) return -1;
    else return max(l1, lol);
}

Compilation message

swap.cpp:15:1: error: expected initializer before 'int'
   15 | int mp[maxn];
      | ^~~
swap.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
swap.cpp:58:9: error: 'e' was not declared in this scope
   58 |         e[i].u = U[i]; e[i].v = V[i]; e[i].w = W[i];
      |         ^
swap.cpp:66:10: error: 'e' was not declared in this scope
   66 |     sort(e, e + m, comp);
      |          ^
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:80:33: error: 'mp' was not declared in this scope; did you mean 'mn'?
   80 |     for (int i = 0; i < n; i++) mp[i] = 0;
      |                                 ^~
      |                                 mn
swap.cpp:84:9: error: 'mp' was not declared in this scope; did you mean 'mn'?
   84 |         mp[x.u]++;
      |         ^~
      |         mn
swap.cpp:90:22: error: 'e' was not declared in this scope
   90 |         if (ans.find(e[i]) == ans.end()){
      |                      ^
swap.cpp:91:17: error: 'mp' was not declared in this scope; did you mean 'mn'?
   91 |             if (mp[e[i].u] || mp[e[i].v]) l1 = min(l1, e[i].w);
      |                 ^~
      |                 mn
In file included from /usr/include/c++/10/string:48,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from swap.cpp:2:
/usr/include/c++/10/bits/stl_function.h: In instantiation of 'constexpr bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = edge]':
/usr/include/c++/10/bits/stl_tree.h:2101: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 = edge; _Val = edge; _KeyOfValue = std::_Identity<edge>; _Compare = std::less<edge>; _Alloc = std::allocator<edge>; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::key_type = edge]'
/usr/include/c++/10/bits/stl_tree.h:2154:4:   required from 'std::pair<std::_Rb_tree_iterator<_Val>, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(_Arg&&) [with _Arg = edge; _Key = edge; _Val = edge; _KeyOfValue = std::_Identity<edge>; _Compare = std::less<edge>; _Alloc = std::allocator<edge>]'
/usr/include/c++/10/bits/stl_set.h:521:25:   required from 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Allocator>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::value_type&&) [with _Key = edge; _Compare = std::less<edge>; _Alloc = std::allocator<edge>; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Allocator>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<edge, edge, std::_Identity<edge>, std::less<edge>, std::allocator<edge> >::const_iterator; std::set<_Key, _Compare, _Alloc>::value_type = edge]'
swap.cpp:45:33:   required from here
/usr/include/c++/10/bits/stl_function.h:386:20: error: no match for 'operator<' (operand types are 'const edge' and 'const edge')
  386 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/vector:60,
                 from swap.h:1,
                 from swap.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:489:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator<(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)'
  489 |     operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_pair.h:489:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10/string:48,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from swap.cpp:2:
/usr/include/c++/10/bits/stl_function.h:386:20: note:   'const edge' is not derived from 'const std::pair<_T1, _T2>'
  386 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/vector:60,
                 from swap.h:1,
                 from swap.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:366:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)'
  366 |     operator<(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:366:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10/string:48,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from swap.cpp:2:
/usr/include/c++/10/bits/stl_function.h:386:20: note:   'const edge' is not derived from 'const std::reverse_iterator<_Iterator>'
  386 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/vector:60,
                 from swap.h:1,
                 from swap.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:404:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)'
  404 |     operator<(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:404:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10/string:48,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from swap.cpp:2:
/usr/include/c++/10/bits/stl_function.h:386:20: note:   'const edge' is not derived from 'const std::reverse_iterator<_Iterator>'
  386 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/vector:60,
                 from swap.h:1,
                 from swap.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:1451:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)'
 1451 |     operator<(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:1451:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10/string:48,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from swap.cpp:2:
/usr/include/c++/10/bits/stl_function.h:386:20: note:   'const edge' is not derived from 'const std::move_iterator<_IteratorL>'
  386 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:67,
                 from /usr/include/c++/10/vector:60,
                 from swap.h:1,
                 from swap.cpp:1:
/usr/include/c++/10/bits/stl_iterator.h:1507:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator<(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorL>&)'
 1507 |     operator<(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_iterator.h:1507:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10/string:48,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from swap.cpp:2:
/usr/include/c++/10/bits/stl_function.h:386:20: note:   'const edge' is not derived from 'const std::move_iterator<_IteratorL>'
  386 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/10/vector:67,
                 from swap.h:1,
                 from swap.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1930:5: note: candidate: 'template<class _Tp, class _Alloc> bool std::operator<(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)'
 1930 |     operator<(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
      |     ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1930:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10/string:48,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from swap.cpp:2:
/usr/include/c++/10/bits/stl_function.h:386:20: note:   'const edge' is not derived from 'const std::vector<_Tp, _Alloc>'
  386 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/10/bits/basic_string.h:48,
                 from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from swap.cpp:2:
/usr/include/c++/10/string_view:544:5: note: candidate: 'template<class _CharT, class _Traits> constexpr bool std::operator<(std::basic_string_view<_CharT, _Traits>, std::basic_string_view<_CharT, _Traits>)'
  544 |     operator< (basic_string_view<_CharT, _Traits> __x,
      |     ^~~~~~~~
/usr/include/c++/10/string_view:544:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10/string:48,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from swap.cpp:2:
/usr/include/c++/10/bits/stl_function.h:386:20: note:   'edge' is not derived from 'std::basic_string_view<_CharT, _Traits>'
  386 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/10/bits/basic_string.h:48,
                 from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from swap.cpp:2:
/usr/include/c++/10/string_view:550:5: note: candidate: 'template<class _CharT, class _Traits> constexpr bool std::operator<(std::basic_string_view<_CharT, _Traits>, std::__type_identity_t<std::basic_string_view<_CharT, _Traits> >)'
  550 |     operator< (basic_string_view<_CharT, _Traits> __x,
      |     ^~~~~~~~
/usr/include/c++/10/string_view:550:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10/string:48,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from swap.cpp:2:
/usr/include/c++/10/bits/stl_function.h:386:20: note:   'edge' is not derived from 'std::basic_string_view<_CharT, _Traits>'
  386 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/10/bits/basic_string.h:48,
                 from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from swap.cpp:2:
/usr/include/c++/10/string_view:557:5: note: candidate: 'template<class _CharT, class _Traits> constexpr bool std::operator<(std::__type_identity_t<std::basic_string_view<_CharT, _Traits> >, std::basic_string_view<_CharT, _Traits>)'
  557 |     operator< (__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
      |     ^~~~~~~~
/usr/include/c++/10/string_view:557:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10/string:48,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from swap.cpp:2:
/usr/include/c++/10/bits/stl_function.h:386:20: note:   'edge' is not derived from 'std::basic_string_view<_CharT, _Traits>'
  386 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from swap.cpp:2:
/usr/include/c++/10/bits/basic_string.h:6267:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&, const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 6267 |     operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/10/bits/basic_string.h:6267:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/10/string:48,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from swap.cpp:2:
/usr/include/c++/10/bits/stl_function.h:386:20: note:   'const edge' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
  386 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/