Submission #1052996

#TimeUsernameProblemLanguageResultExecution timeMemory
1052996noyancanturkKeys (IOI21_keys)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
using pii=pair<int,int>;

const int lim=3e5+100;
int n,m;

vector<pii>v[lim],r;
bool havekey[lim];
vector<int>willvis[lim];
bool vis[lim];

void dfs(int node){
    if(vis[node])continue;
    vis[node]=1;
    if(!havekey[r[node]]){
        havekey[r[node]]=1;
        for(int j:willvis[r[node]]){
            dfs(j);
        }
    }
    for(auto[j,c]:v[node]){
        if(havekey[c]){
            dfs(j);
        }else{
            willvis[c].pb(j);
        }
    }
}

vector<int> find_reachable(vector<int> R, vector<int> U, vector<int> V, vector<int> c) {
	n=r.size(),m=u.size();
    r=R;
    for(int i=0;i<m;i++){
        v[U[i]].pb({V[i],c[i]});
        v[V[i]].pb({U[i],c[i]});
    }
	int res=INT_MAX;
	vector<int>ans;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            vis[j]=0;
            havekey[j]=0;
            willvis[j].clear();
        }
        dfs(i);
        int cnt=0;
        for(int j=0;j<n;j++){
            if(vis[j])cnt++;
        }
        if(res<cnt){
            res=cnt;
            ans.clear();
        }
        if(res==cnt){
            ans.pb(i);
        }
    }
	vector<int>finalans(n,0);
	for(int i:ans){
		finalans[i]=1;
	}
	return finalans;
}

Compilation message (stderr)

keys.cpp: In function 'void dfs(int)':
keys.cpp:16:18: error: continue statement not within a loop
   16 |     if(vis[node])continue;
      |                  ^~~~~~~~
keys.cpp:18:16: error: no match for 'operator[]' (operand types are 'bool [300100]' and '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'})
   18 |     if(!havekey[r[node]]){
      |                ^
keys.cpp:19:16: error: no match for 'operator[]' (operand types are 'bool [300100]' and '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'})
   19 |         havekey[r[node]]=1;
      |                ^
keys.cpp:20:26: error: no match for 'operator[]' (operand types are 'std::vector<int> [300100]' and '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'})
   20 |         for(int j:willvis[r[node]]){
      |                          ^
keys.cpp: In function 'std::vector<int> find_reachable(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
keys.cpp:34:15: error: 'u' was not declared in this scope
   34 |  n=r.size(),m=u.size();
      |               ^
keys.cpp:35:7: error: no match for 'operator=' (operand types are 'std::vector<std::pair<int, int> >' and 'std::vector<int>')
   35 |     r=R;
      |       ^
In file included from /usr/include/c++/10/vector:72,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from keys.cpp:1:
/usr/include/c++/10/bits/vector.tcc:198:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >]'
  198 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/vector.tcc:199:42: note:   no known conversion for argument 1 from 'std::vector<int>' to 'const std::vector<std::pair<int, int> >&'
  199 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from keys.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:709:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >]'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:709:26: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::vector<std::pair<int, int> >&&'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:730:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >]'
  730 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:730:46: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::initializer_list<std::pair<int, int> >'
  730 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~