Submission #422259

#TimeUsernameProblemLanguageResultExecution timeMemory
422259dreezy친구 (IOI14_friend)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include "friend.h" using namespace std; /*******************/ #define pi pair<int,int> #define ll long long #define f first #define s second #define pb push_back struct UnionFind{ vector<int> parent, height, sz; void init(int n){ height.clear(); height.assign(n, 0); parent.clear(); parent.assign(n, 0); sz.clear(); sz.assign(n, 1); for(int i=0; i<n ;i++){ parent[i] = i; } } int root(int n){ if(parent[n]!= n) parent[n] = root(parent[n]); return parent[n]; } bool same(int n1, int n2){ return root(n1) == root(n2); } void join(int n1, int n2){ int r1 = root(n1); int r2 = root(n2); if(height[r1] > height[r2]){ parent[r2] = r1; height[r1] = max(height[r1], height[r2] + 1); sz[r1] += sz[r2]; //cout << sz[r1]<<"; "<<sz[r2]<<endl; }else{ parent[r1] = r2; height[r2] = max(height[r2], height[r1] + 1); sz[r2]+=sz[r1]; //cout << sz[r1]<<";; "<<sz[r2]<<endl; } } }; int findSample(int n,int confidence[],int host[],int protocol[]){ UnionFind uf; uf.init(n); for(int i =1; i<n; i++){ if(protocol[i] == 1){ uf.join(i, host[i]); //cout << i <<", "<<host[i]<<endl; } } set<int> roots; for(int i =0;i < n; i++){ roots.insert(uf.root(i)); } int ans =0; for(int rt : roots){ //cout <<rt<<": "<< uf.sz[rt]<<endl; ans = max(ans, uf.sz[rt]); } return max(ans, roots.size()); } /*******************/

Compilation message (stderr)

friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:81:30: error: no matching function for call to 'max(int&, std::set<int>::size_type)'
   81 |  return max(ans, roots.size());
      |                              ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from friend.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
friend.cpp:81:30: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::set<int>::size_type' {aka 'long unsigned int'})
   81 |  return max(ans, roots.size());
      |                              ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from friend.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
friend.cpp:81:30: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::set<int>::size_type' {aka 'long unsigned int'})
   81 |  return max(ans, roots.size());
      |                              ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from friend.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
friend.cpp:81:30: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   81 |  return max(ans, roots.size());
      |                              ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from friend.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
friend.cpp:81:30: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   81 |  return max(ans, roots.size());
      |                              ^