Submission #720595

# Submission time Handle Problem Language Result Execution time Memory
720595 2023-04-08T15:09:30 Z Ahmed57 Mag (COCI16_mag) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;
vector<int> adj[1000006];
long long ma[1000006];
long long lon[1000006];
int n ;
void calc(int i,int pr){
    long long ch = (ma[i]==1?1:0);
    for(auto j:adj[i]){
        if(j!=pr){
            calc(j,i);
            if(ma[i]==1)ch = max(ch,lon[j]+1);
        }
    }
    lon[i] = ch;
}
long long maa = 0;
void dfs(int i,int pr){
    maa = max(maa,lon[i]);
    for(auto j:adj[i]){
        if(j==pr)continue;
        dfs(j,i);
    }
    if(ma[i]==1){
        long long firstma = 0 , secondma = 0;
        for(auto j:adj[i]){
            if(j==pr)continue;
            if(firstma<=lon[j]){
                secondma = firstma;
                firstma = lon[j];
            }else if(secondma<=lon[j]){
                secondma = lon[j];
            }
        }
        maa = max(maa,firstma+secondma+1);
    }
}
bool ss = 0;
void reroor(int i,int pr,int cnt){
    if(ma[i]==2){
        long long firstma = cnt , secondma = 0;
        for(auto j:adj[i]){
            if(j==pr)continue;
            if(firstma<=lon[j]){
                secondma = firstma;
                firstma = lon[j];
            }else if(secondma<=lon[j]){
                secondma = lon[j];
            }
        }
        if(firstma==secondma&&firstma==maa){
            ss = 1;
        }
    }
    vector<int> pref,suf,ch;
    int mm= 0;
    for(auto j:adj[i]){
        if(j==pr)continue;
        mm = max(mm,lon[j]);
        pref.push_back(mm);
        ch.push_back(j);
    }
    mm = cnt;suf.push_back(mm);
    reverse(ch.begin(),ch.end());
    for(auto j:ch){
        mm = max(mm,lon[j]);
        suf.push_back(mm);
    }
    reverse(suf.begin(),suf.end());
    reverse(ch.begin(),ch.end());
    for(int j = 0;j<ch.size();j++){
        reroor(ch[j],i,(ma[i]==1?max(suf[j+1],(j==0?0:pref[j-1]))+1:0));
    }
}
signed main(){
    cin>>n;
    for(int i = 0;i<n-1;i++){
        int a,b;cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    long long mi = 1e18;
    for(int i = 0;i<n;i++){
        cin>>ma[i+1];
        mi = min(mi,ma[i+1]);
    }
    if(mi!=1){
        cout<<mi<<"/"<<1<<endl;
        return 0;
    }
    calc(1,0);
    dfs(1,0);
    reroor(1,0,0);
    if(ss) cout<<2<<"/"<<2*maa+1<<endl;
    else cout<<1<<"/"<<maa<<endl;
}

Compilation message

mag.cpp: In function 'void reroor(int, int, int)':
mag.cpp:60:27: error: no matching function for call to 'max(int&, long long int&)'
   60 |         mm = max(mm,lon[j]);
      |                           ^
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 mag.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:
mag.cpp:60:27: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   60 |         mm = max(mm,lon[j]);
      |                           ^
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 mag.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:
mag.cpp:60:27: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   60 |         mm = max(mm,lon[j]);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from mag.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:
mag.cpp:60:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   60 |         mm = max(mm,lon[j]);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from mag.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:
mag.cpp:60:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   60 |         mm = max(mm,lon[j]);
      |                           ^
mag.cpp:67:27: error: no matching function for call to 'max(int&, long long int&)'
   67 |         mm = max(mm,lon[j]);
      |                           ^
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 mag.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:
mag.cpp:67:27: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   67 |         mm = max(mm,lon[j]);
      |                           ^
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 mag.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:
mag.cpp:67:27: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   67 |         mm = max(mm,lon[j]);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from mag.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:
mag.cpp:67:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   67 |         mm = max(mm,lon[j]);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from mag.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:
mag.cpp:67:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   67 |         mm = max(mm,lon[j]);
      |                           ^
mag.cpp:72:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     for(int j = 0;j<ch.size();j++){
      |                   ~^~~~~~~~~~