Submission #1021913

#TimeUsernameProblemLanguageResultExecution timeMemory
1021913nisanduuSplit the Attractions (IOI19_split)C++14
Compilation error
0 ms0 KiB
#include "split.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; map<ll,char> hash; map<char,ll> mp; ll n1,n2; ll dfs(ll& cr,vector<pair<ll,char>> &v,ll node,vector<vector<ll>>&adj,ll parent){ ll am = 1; for(auto el:adj[node]){ if(el!=parent){ am += dfs(cr,v,el,adj,node); if(cr>=2) return 0; if(am>=v[cr].first){ if(cr==0) n1=el; else n2=el; hash[el]=v[cr].second; return 0; } } } return am; } void dfs2(ll node,vector<vector<ll>>&adj,ll parent,ll cnt,char let,ll target){ if(node==target){ dfs3(node,adj,parent,cnt,let); return; } for(auto el:adj[node]){ if(el!=parent){ dfs2(el,adj,node,cnt,let,target); } } } void dfs3(ll node,vector<vector<ll>>&adj,ll parent,ll &cnt,char let){ if(cnt==0) return; if(hash[node] != let) return; res[node]=mp[let]; cnt--; for(auto el:adj[node]){ if(el!=parent){ dfs3(el,adj,node,cnt,let); } } } vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) { ll A=a,B=b,C=c; vector<int> res(n); int m = p.size(); vector<vector<int>> adj(n+2); for(int i=0;i<m;i++){ adj[p[i]].push_back(q[i]); adj[q[i]].push_back(p[i]); } vector<int> vis(n+2); if(m == n-1){ mp['A']=1; mp['B']=c; mp['C']=3; vector<pair<ll,char>> v; v.push_back({A,'A'}); v.push_back({B,'B'}); v.push_back({C,'C'}); sort(v.begin(),v.end()); ll parentNode = 0; ll am = dfs(0,v,parentNode,adj,-1); if(cr<2&&am>=v[cr].first){ mp[parentNode] = v[cr].second; } dfs2(parentNode,adj,-1,v[0].first,v[0].second,n1); dfs2(parentNode,adj,-1,v[1].first,v[1].second,n2); for(ll i=0;i<n;i++){ if(res[i]==0){ res[i]=mp[v[2].second]; } } return res; } bool f1=0; if(B>C){ swap(B,C); f1=1; } stack<int> ds; ds.push(0); vector<int> vis1(n+10); while(!ds.empty()){ int node = ds.top(); ds.pop(); if(vis1[node]) continue; vis1[node]=1; if(B>0){ res[node]=f1 ? 3 : 2; B--; }else if(A>0){ A--; res[node]=1; }else{ C--; res[node]=f1 ? 2 : 3; } for(auto el:adj[node]){ if(!vis1[el]){ ds.push(el); } } } assert(A==0&&B==0&&C==0); return res; }

Compilation message (stderr)

split.cpp: In function 'll dfs(ll&, std::vector<std::pair<long long int, char> >&, ll, std::vector<std::vector<long long int> >&, ll)':
split.cpp:18:14: error: reference to 'hash' is ambiguous
   18 |              hash[el]=v[cr].second;
      |              ^~~~
In file included from /usr/include/c++/10/bits/stl_bvector.h:61,
                 from /usr/include/c++/10/vector:68,
                 from split.h:5,
                 from split.cpp:1:
/usr/include/c++/10/bits/functional_hash.h:58:12: note: candidates are: 'template<class _Tp> struct std::hash'
   58 |     struct hash;
      |            ^~~~
split.cpp:6:14: note:                 'std::map<long long int, char> hash'
    6 | map<ll,char> hash;
      |              ^~~~
split.cpp: In function 'void dfs2(ll, std::vector<std::vector<long long int> >&, ll, ll, char, ll)':
split.cpp:28:9: error: 'dfs3' was not declared in this scope; did you mean 'dfs2'?
   28 |         dfs3(node,adj,parent,cnt,let);
      |         ^~~~
      |         dfs2
split.cpp: In function 'void dfs3(ll, std::vector<std::vector<long long int> >&, ll, ll&, char)':
split.cpp:40:8: error: reference to 'hash' is ambiguous
   40 |     if(hash[node] != let) return;
      |        ^~~~
In file included from /usr/include/c++/10/bits/stl_bvector.h:61,
                 from /usr/include/c++/10/vector:68,
                 from split.h:5,
                 from split.cpp:1:
/usr/include/c++/10/bits/functional_hash.h:58:12: note: candidates are: 'template<class _Tp> struct std::hash'
   58 |     struct hash;
      |            ^~~~
split.cpp:6:14: note:                 'std::map<long long int, char> hash'
    6 | map<ll,char> hash;
      |              ^~~~
split.cpp:41:5: error: 'res' was not declared in this scope
   41 |     res[node]=mp[let];
      |     ^~~
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:69:21: error: cannot bind non-const lvalue reference of type 'll&' {aka 'long long int&'} to an rvalue of type 'll' {aka 'long long int'}
   69 |         ll am = dfs(0,v,parentNode,adj,-1);
      |                     ^
split.cpp:9:12: note: in passing argument 1 of 'll dfs(ll&, std::vector<std::pair<long long int, char> >&, ll, std::vector<std::vector<long long int> >&, ll)'
    9 | ll dfs(ll& cr,vector<pair<ll,char>> &v,ll node,vector<vector<ll>>&adj,ll parent){
      |        ~~~~^~
split.cpp:70:12: error: 'cr' was not declared in this scope; did you mean 'c'?
   70 |         if(cr<2&&am>=v[cr].first){
      |            ^~
      |            c
split.cpp:74:25: error: invalid initialization of reference of type 'std::vector<std::vector<long long int> >&' from expression of type 'std::vector<std::vector<int> >'
   74 |         dfs2(parentNode,adj,-1,v[0].first,v[0].second,n1);
      |                         ^~~
split.cpp:26:38: note: in passing argument 2 of 'void dfs2(ll, std::vector<std::vector<long long int> >&, ll, ll, char, ll)'
   26 | void dfs2(ll node,vector<vector<ll>>&adj,ll parent,ll cnt,char let,ll target){
      |                   ~~~~~~~~~~~~~~~~~~~^~~
split.cpp:75:25: error: invalid initialization of reference of type 'std::vector<std::vector<long long int> >&' from expression of type 'std::vector<std::vector<int> >'
   75 |         dfs2(parentNode,adj,-1,v[1].first,v[1].second,n2);
      |                         ^~~
split.cpp:26:38: note: in passing argument 2 of 'void dfs2(ll, std::vector<std::vector<long long int> >&, ll, ll, char, ll)'
   26 | void dfs2(ll node,vector<vector<ll>>&adj,ll parent,ll cnt,char let,ll target){
      |                   ~~~~~~~~~~~~~~~~~~~^~~