Submission #540367

# Submission time Handle Problem Language Result Execution time Memory
540367 2022-03-20T06:49:47 Z BadPenalty Logičari (COCI21_logicari) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define all(x) x.begin(),x.end()
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
const int N = 2e5,mod = 1e9+7;
 
vector<int>adj[N];
int head[N],par[N];
int root,special;
int dp[N][2][2][2][2];
int st(int x)
{
    if (x == head[x]) return x;
    return head[x] = st(head[x]);
}
 
void dfs(int x,int pr)
{
    par[x] = pr;
    for(auto u:adj[x])
    {
        if(u == pr)continue;
        dfs(u,x);
    }
}
 
int calc(int nd,int me,int up,int rt,int sp)
{
    if(dp[nd][me][up][rt][sp]!=-1)
        return dp[nd][me][up][rt][sp];
    bool tr = 1;
    if(nd==special&&rt&&up)tr = 0;
    if(nd==root&&me!=rt)tr = 0;
    if(nd==special&&me!=sp)tr = 0;
    if(!tr)
        return dp[nd][me][up][rt][sp] = 1e9;
    ll sum = me;
    for(auto u:adj[nd])
    {
        if(u==par[nd])continue;
        sum+=calc(u,0,me,rt,sp);
    }
    bool cmp = 0;
    if(up)cmp = 1;
    if(nd==root&&sp)cmp = 1;
    if(nd==special&&rt)cmp = 1;
 
    ll res = 1e9;
    if(cmp)
    {
        res = min(res,sum);
    }
    else
    {
        for(auto u:adj[nd])
        {
            if(u==par[nd])continue;
            ll val = sum-calc(u,0,me,rt,sp)+calc(u,1,me,rt,sp);
            res = min(res,val);;
        }
    }
    return dp[nd][me][up][rt][sp] = res;
 
 
}
 
 
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
 
    for(int i = 0;i<=n;i++)
        head[i] = i;
    for(int i = 0;i<n;i++)
    {
        int a,b;
        cin>>a>>b;
 
        int pa = st(a);
        int pb = st(b);
 
        if(pa==pb)
        {
            root = a;
            special = b;
        }
        else
        {
            head[pa] = pb;
            adj[a].pb(b);
            adj[b].pb(a);
        }
    }
    dfs(root,0);
    ll ans = 1e9;
//    cout<<root<<' '<<special<<endl;
    memset(dp,-1,sizeof dp);
    for(int rt = 0;rt<=1;rt++)
    {
        for(int sp = 0;sp<=1;sp++)
        {
//            cout<<calc(root,rt,0,rt,sp)<<' '<<endl;
//            cout<<rt<<' '<<sp<<endl;
            ans = min(ans,calc(root,rt,0,rt,sp));
        }
    }
    if(ans==1e9)
        cout<<-1<<endl;
    else
        cout<<ans<<endl;
    return 0;
}
/*
 
*/

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:114:48: error: no matching function for call to 'min(ll&, int)'
  114 |             ans = min(ans,calc(root,rt,0,rt,sp));
      |                                                ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 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 Main.cpp:1:
/usr/include/c++/10/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++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
Main.cpp:114:48: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  114 |             ans = min(ans,calc(root,rt,0,rt,sp));
      |                                                ^
In file included from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 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 Main.cpp:1:
/usr/include/c++/10/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++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
Main.cpp:114:48: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  114 |             ans = min(ans,calc(root,rt,0,rt,sp));
      |                                                ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
Main.cpp:114:48: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  114 |             ans = min(ans,calc(root,rt,0,rt,sp));
      |                                                ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
Main.cpp:114:48: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  114 |             ans = min(ans,calc(root,rt,0,rt,sp));
      |                                                ^