제출 #1207031

#제출 시각아이디문제언어결과실행 시간메모리
1207031em4ma2바이오칩 (IZhO12_biochips)C++20
컴파일 에러
0 ms0 KiB
//                                 اللهم صل على محمد وعلى ال محمد كما صليت على ابراهيم وعلى ال ابراهيم انك حميد مجيد
#include "bits/stdc++.h"

using namespace std;

#define ll long long
//#define int long long
#define pb push_back
#define applejuice ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

const int mod=1e9+7;
const ll inf=1e9;
const int mxsz=2e5+4;
const int off=1<<20;
const int siz=504;

vector<ll>adj[mxsz];
int vis[mxsz];
ll a[mxsz];
ll dp[mxsz][siz];
ll sz[mxsz];

void dfs(int i){
    vis[i]=1;
    for (auto x:adj[i]){
        if (!vis[x]){
            dfs(x);
            sz[i]+=sz[x];
        }
    }
}

void tra(int i,int m){
    vis[i]=1;
    for (auto x:adj[i]) {
        if (!vis[x])tra(x,m);
        //cout<<"sdj;";
        for (int j = m; j >=0; j--) {
            for (int l = min(sz[x],j); l >=0; l--) {
                dp[i][j]=max(dp[i][j],dp[x][l]+dp[i][j-l]);
            }
        }
    }
    dp[i][1]=max(dp[i][1],a[i]);
}

signed main(){
    applejuice;

    int n,m;
    cin>>n>>m;
    int root;
    for (int i=1;i<=n;i++){
        int p, x;
        cin>>p>>x;
        a[i]=x;
        if (p==0)root=i;
        adj[p].pb(i);
    }
    for (int i=0;i<=n;i++){
        for (int j=0;j<=m;j++){
            dp[i][j]=-inf;
        }
    }
    for (int i=0;i<=n;i++){
        dp[i][0]=0;
    }
    /*for (int i=1;i<=n;i++){
        if (adj[i].size()==0){
            dp[i][1]=a[i];
        }
    }*/
    for (int i=1;i<=n;i++){
        sz[i]=1;
    }
    dfs(root);
    for (int i=0;i<=n;i++)vis[i]=0;
    tra(root,m);
    /*for (int i=1;i<n;i++){
        for (int j=1;j<=m;j++){
            cout<<dp[i][j]<<" ";
        }
    }*/
    cout<<dp[root][m]<<endl;
}

컴파일 시 표준 에러 (stderr) 메시지

biochips.cpp: In function 'void tra(int, int)':
biochips.cpp:39:29: error: no matching function for call to 'min(long long int&, int&)'
   39 |             for (int l = min(sz[x],j); l >=0; l--) {
      |                          ~~~^~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from biochips.cpp:2:
/usr/include/c++/11/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
biochips.cpp:39:29: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   39 |             for (int l = min(sz[x],j); l >=0; l--) {
      |                          ~~~^~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from biochips.cpp:2:
/usr/include/c++/11/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
biochips.cpp:39:29: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   39 |             for (int l = min(sz[x],j); l >=0; l--) {
      |                          ~~~^~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from biochips.cpp:2:
/usr/include/c++/11/bits/stl_algo.h:3449:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3449 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3449:5: note:   template argument deduction/substitution failed:
biochips.cpp:39:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   39 |             for (int l = min(sz[x],j); l >=0; l--) {
      |                          ~~~^~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from biochips.cpp:2:
/usr/include/c++/11/bits/stl_algo.h:3455:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3455 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3455:5: note:   template argument deduction/substitution failed:
biochips.cpp:39:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   39 |             for (int l = min(sz[x],j); l >=0; l--) {
      |                          ~~~^~~~~~~~~