답안 #212506

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
212506 2020-03-23T09:57:40 Z toxic_hack Mag (COCI16_mag) C++11
컴파일 오류
0 ms 0 KB
// g++ -std=c++14

/*

Today might be the chance to grasp the chance to let your talent bloom.
May be tomorrow, the day after, or next year...
May be even when you are 30. I'm not sure if physique has anything to do with it
but if you think that it will never come, it probably never will.

- Tooru Oikawa.

*/


#include<bits/stdc++.h>

typedef long long ll;
typedef long double lld;
using namespace std;

#define endl "\n"
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(c) c.begin(),c.end()
#define pii pair<int, int>
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
ll l=v.size();for(ll i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template <typename T>
ostream &operator<<(ostream &out, set<T> const &v) {
    for (auto i = v.begin(); i != v.end(); i++)
        out << (*i) << ' ';
    return out;
}
template <typename T, typename V>
ostream &operator<<(ostream &out, map<T, V> const &v) {
    for (auto i = v.begin(); i != v.end(); i++)
        out << "\n" << (i->first) <<  ":"  << (i->second);
    return out;
}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

// #define int ll

const int N = 2e6 + 100;

int n;
vector<vector<int>> g(N);
int arr[N];

int dp_down[N], dp_up[N];
int parent[N];
int ans0 = 0;
void dfs0(int v, int p) {
    parent[v] = p;
    int curr = (arr[v] == 1);
    vector<int> child;
    for (auto u : g[v]) {
        if (u == p)  continue;
        dfs0(u, v);
        curr = max(curr, dp_down[u] + 1);
        child.push_back(dp_down[u]);
    }
    if (arr[v] == 1) {
        dp_down[v] = curr;
        if (child.empty()) {
            ans0 = max(ans0, 1LL);
        } else if ((int)child.size() == 1) {
            ans0 = max(ans0, child.back() + 1);
        } else {
            sort(all(child));
            reverse(all(child));
            ans0 = max(ans0, child[0] + child[1] + 1LL);
        }
    }
}

void dfs1(int v, int p, int mx_len = 0) {
    // tr(v, mx_len);
    dp_up[v] = mx_len;
    if (arr[v] == 1) {
        multiset<int> child;
        child.insert(mx_len);
        for (auto u : g[v]) {
            if (u == p) continue;
            child.insert(dp_down[u]);
        }

        for (auto u : g[v]) {
            if (u == p) continue;
            auto itr = child.find(dp_down[u]);
            if (itr == child.end()) {
                cout << "hahah" << endl;
            } else {
                child.erase(child.find(dp_down[u]));
                int heremx = *child.rbegin() + 1;
                dfs1(u, v, heremx);
                child.insert(dp_down[u]);
            }
        }

    } else {
        for (auto u : g[v]) {
            if (u == p) continue;
            dfs1(u, v, 0);
        }
    }
}

int cmp(int a, int b, int c, int d) {
    return (a * d < c * b);
}

const int inf = 1e9 + 1;
int solve() {
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int v, u;
        cin >> v >> u;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for (int i = 1; i <= n; i++) {
        cin >> arr[i];
    }
    dfs0(1, 0);
    dfs1(1, 0);

    if (ans0 == 0) {
        int mi = inf;
        for (int i = 1; i <= n; i++) {
            mi = min(mi, arr[i]);
        }
        cout << mi << "/1" << endl;
    } else {
        int a = 1, b = ans0;
        for (int i = 1; i <= n; i++) {
            vector<int> pth;
            for (auto j : g[i]) {
                if (j == parent[i]) continue;
                pth.push_back(dp_down[j]);
            }
            pth.push_back(dp_up[i]);
            sort(all(pth));
            reverse(all(pth));
            // tr(i, pth, a, b);
            if ((int)pth.size() == 1) {
                int c = arr[i], d = pth[0] + 1;
                if (!cmp(a, b, c, d)) {
                    a = c, b = d;
                }
            } else {
                int c = arr[i], d = 1 + pth[0] + pth[1];
                if (!cmp(a, b, c, d)) {
                    a = c, b = d;
                }
            }
        }
        assert(b != 0 && a != 0);
        int g = __gcd(a, b);
        a /= g;
        b /= g;
        cout << a << "/" << b << endl;
    }
    return 0;
}

int32_t main(){ _
    int t;
    // cin >> t;
    t = 1;
    while (t--) solve();
}

Compilation message

mag.cpp: In function 'void dfs0(int, int)':
mag.cpp:83:33: error: no matching function for call to 'max(int&, long long int)'
             ans0 = max(ans0, 1LL);
                                 ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from mag.cpp:15:
/usr/include/c++/7/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
mag.cpp:83:33: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
             ans0 = max(ans0, 1LL);
                                 ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from mag.cpp:15:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
mag.cpp:83:33: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
             ans0 = max(ans0, 1LL);
                                 ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from mag.cpp:15:
/usr/include/c++/7/bits/stl_algo.h:3462:5: note: candidate: template<class _Tp> _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
mag.cpp:83:33: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
             ans0 = max(ans0, 1LL);
                                 ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from mag.cpp:15:
/usr/include/c++/7/bits/stl_algo.h:3468:5: note: candidate: template<class _Tp, class _Compare> _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
mag.cpp:83:33: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
             ans0 = max(ans0, 1LL);
                                 ^
mag.cpp:89:55: error: no matching function for call to 'max(int&, long long int)'
             ans0 = max(ans0, child[0] + child[1] + 1LL);
                                                       ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from mag.cpp:15:
/usr/include/c++/7/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
mag.cpp:89:55: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
             ans0 = max(ans0, child[0] + child[1] + 1LL);
                                                       ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from mag.cpp:15:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
mag.cpp:89:55: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
             ans0 = max(ans0, child[0] + child[1] + 1LL);
                                                       ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from mag.cpp:15:
/usr/include/c++/7/bits/stl_algo.h:3462:5: note: candidate: template<class _Tp> _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
mag.cpp:89:55: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
             ans0 = max(ans0, child[0] + child[1] + 1LL);
                                                       ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from mag.cpp:15:
/usr/include/c++/7/bits/stl_algo.h:3468:5: note: candidate: template<class _Tp, class _Compare> _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
mag.cpp:89:55: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
             ans0 = max(ans0, child[0] + child[1] + 1LL);
                                                       ^