답안 #870102

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
870102 2023-11-07T00:12:36 Z Ahmed_Solyman Stranded Far From Home (BOI22_island) C++14
컴파일 오류
0 ms 0 KB
/*
In the name of Allah
made by: Ahmed_Solyman
*/
#include <bits/stdc++.h>
#include <ext/rope>
 
using namespace std;
using namespace __gnu_cxx;
#pragma GCC optimize("-Ofast")
#pragma GCC optimize("-O1")
//-------------------------------------------------------------//
typedef long long ll;
typedef unsigned long long ull;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sum_to(n) (n*(n+1))/2
#define pb push_back
#define pf push_front
#define fil(arr,x) memset(arr,x,sizeof(arr))
const ll mod=1e9+7;
int dx[8]={0,1,0,-1,1,1,-1,-1};
int dy[8]={1,0,-1,0,1,-1,-1,1};
//-------------------------------------------------------------//
ll lcm(ll a,ll b)
{
    return (max(a,b)/__gcd(a,b))*min(a,b);
}
void person_bool(bool x)
{
    cout<<(x?"YES":"NO")<<endl;
}
const int N=2e5+5;
int ans[N],arr[N],n,m;
vector<int>adj[N];
struct DSU{
    vector<int>P,sz,sum;
    vector<vector<int>>ok;
    void init(int n){
        P.resize(n+5);
        ok.resize(n+5);
        sum.resize(n+5);
        sz.resize(n+5);
        for(int i=0;i<n+5;i++)sz[i]=1,sum[i]=arr[i],P[i]=i,ok[i].push_back(i);
    }
    int find(int node){
        if(P[node]==node)return node;
        return P[node]=find(P[node]);
    }
    bool unite(int a,int b){
        int p1=find(a);
        int p2=find(b);
        if(p1==p2){
            return 0;
        }
        if(sz[p1]<sz[p2])swap(p1,p2);
        for(auto i:ok[p2])ok[p1].push_back(i);
        ok[p2].clear();
        P[p2]=p1;
        sum[p2]+=sum[p1];
        sz[p1]+=sz[p2];
        return 1;
    }
}d;
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #ifndef ONLINE_JUDGE
    //freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
    #endif
    fast
    cin>>n>>m;
    vector<pair<int,int>>v;
    for(int i=1;i<=n;i++){
        cin>>arr[i];ans[i]=1;
        v.push_back({arr[i],i});
    }
    while(m--){
        int u,v;cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    d.init(n);
    sort(all(v));
    for(int i=0;i<n;i++){
        int node=v[i].second,x=v[i].first;
        for(auto ch:adj[node]){
            if(arr[ch]>arr[node] || (arr[ch]==arr[node] && ch>node))continue;
            if(d.sum[d.find(ch)]<arr[node]){
                for(auto j:d.ok[find(ch)])ans[j]=0;
                d.ok[d.find(ch)].clear();
            }
            d.unite(node,ch);
        }
    }
    for(int i=1;i<=n;i++){
        cout<<ans[i];
    }
    cout<<endl;
    return 0;
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:97:40: error: no matching function for call to 'find(int&)'
   97 |                 for(auto j:d.ok[find(ch)])ans[j]=0;
      |                                        ^
In file included from /usr/include/c++/10/bits/locale_facets.h:48,
                 from /usr/include/c++/10/bits/basic_ios.h:37,
                 from /usr/include/c++/10/ios:44,
                 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 island.cpp:5:
/usr/include/c++/10/bits/streambuf_iterator.h:422:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(std::istreambuf_iterator<_CharT>, std::istreambuf_iterator<_CharT>, const _CharT2&)'
  422 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/10/bits/streambuf_iterator.h:422:5: note:   template argument deduction/substitution failed:
island.cpp:97:40: note:   mismatched types 'std::istreambuf_iterator<_CharT>' and 'int'
   97 |                 for(auto j:d.ok[find(ch)])ans[j]=0;
      |                                        ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from island.cpp:5:
/usr/include/c++/10/bits/stl_algo.h:3894:5: note: candidate: 'template<class _IIter, class _Tp> _IIter std::find(_IIter, _IIter, const _Tp&)'
 3894 |     find(_InputIterator __first, _InputIterator __last,
      |     ^~~~
/usr/include/c++/10/bits/stl_algo.h:3894:5: note:   template argument deduction/substitution failed:
island.cpp:97:40: note:   candidate expects 3 arguments, 1 provided
   97 |                 for(auto j:d.ok[find(ch)])ans[j]=0;
      |                                        ^
island.cpp:93:30: warning: unused variable 'x' [-Wunused-variable]
   93 |         int node=v[i].second,x=v[i].first;
      |                              ^