Submission #714876

# Submission time Handle Problem Language Result Execution time Memory
714876 2023-03-25T11:34:31 Z Ahmed57 Zagrade (COI17_zagrade) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;
#define int long long
long long sz[300007];long long all = 0;
long long vis[300007];
vector<int> adj[300007];
int ss = 0;
long long zz[300007];
string s;
long long bra = 0;
long long c = 0;
long long ch = 0;
void calc(int no,int pr){
    if(ss==0){
        if(s[no-1]=='('){bra++;ch--;ch=max(ch,0LL);}
        if(s[no-1]==')'){bra--;ch++;}
        if(bra>=0&&ch==0)zz[bra]++;
    }else if(ss==1){
        if(s[no-1]=='('){bra++;ch++;}
        if(s[no-1]==')'){bra--;ch--;ch=max(ch,0LL);}
        if(bra<=0&&ch==0){
            all+=zz[-bra];
        }
        //if(bra==0&&ch==0)c++;
    }else{
        if(s[no-1]=='('){bra++;ch--;ch=max(ch,0LL);}
        if(s[no-1]==')'){bra--;ch++;}
        if(bra>=0&&ch==0)zz[bra]--;
    }
    for(auto i:adj[no]){
        if(i==pr||vis[i])continue;
        calc(i,no);
    }
}
int dfs(int no,int pr){
    sz[no] = 1;
    for(auto i:adj[no]){
        if(i==pr||vis[i]!=0)continue;
        sz[no]+=dfs(i,no);
    }
    return sz[no];
}
int get_centroid(int no,int ss,int pr){
    for(auto i:adj[no]){
        if(pr==i||vis[i]!=0)continue;
        if(sz[i]*2>ss){
            return get_centroid(i,ss,no);
        }
    }
    return no;
}
void centroid(int no){
    int cen = get_centroid(no,dfs(no,-1),-1);
    for(int i = 0;i<=max(1000,sz[cen]+5);i++){
        zz[i] = 0;
    }
    zz[0] = 1;
    vis[cen] = 1;
    for(auto i:adj[cen]){
        if(vis[i])continue;
        ss= 0;
        ch = 0;
        bra = 0;
        calc(i,-1);
    }
    if(s[cen-1]==')')all+=zz[1];
    for(auto i:adj[cen]){
        if(vis[i])continue;
        ss = 2;
        ch =0 , bra = 0;
        calc(i,-1);
        ss = 1;
        ch = (s[cen-1]=='('?1:0);
        bra = (s[cen-1]=='('?1:-1);
        calc(i,-1);
        //cout<<all<<" "<<i<<endl;
        bra = 0;
        ch = 0;
        ss = 0;
        calc(i,-1);
    }
    for(auto i:adj[cen]){
        if(vis[i])continue;
        centroid(i);
    }
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n>>s;
    for(int i = 0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    centroid(1);
    cout<<all<<endl;
}

Compilation message

zagrade.cpp: In function 'void centroid(long long int)':
zagrade.cpp:55:40: error: no matching function for call to 'max(int, long long int)'
   55 |     for(int i = 0;i<=max(1000,sz[cen]+5);i++){
      |                                        ^
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 zagrade.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:
zagrade.cpp:55:40: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   55 |     for(int i = 0;i<=max(1000,sz[cen]+5);i++){
      |                                        ^
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 zagrade.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:
zagrade.cpp:55:40: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   55 |     for(int i = 0;i<=max(1000,sz[cen]+5);i++){
      |                                        ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from zagrade.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:
zagrade.cpp:55:40: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   55 |     for(int i = 0;i<=max(1000,sz[cen]+5);i++){
      |                                        ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from zagrade.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:
zagrade.cpp:55:40: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   55 |     for(int i = 0;i<=max(1000,sz[cen]+5);i++){
      |                                        ^