Submission #2487436


Source Code Expand

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <iomanip>
#include <queue>
#include <map>
#include <set>
#include <random>
#include <sstream>
#include <stack>
#include <deque>

using namespace std;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

int n, x;
vi h(100);
vector<vi> G(100);
vi used(100, 0);

ll dfs(int n) {
    ll dd = 0;
    used[n] = 1;
    if (!G[n].size()) {
        if (h[n]) dd = 2;
        else dd = 0;
        return dd;
    }
    for (int v : G[n]) {
        if (!used[v])
            dd += dfs(v);
    }
    if (dd || h[n]) {
        dd = dd + 2;
    } else {
        dd = 0;
    }
    return dd;
}

int main() {
    cin >> n >> x;
    rep(i,n) cin >> h[i];
    rep(i,n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    cout << max(dfs(x-1)-2, 0) << endl;

    return 0;
}

Submission Info

Submission Time
Task B - ツリーグラフ
User bluenote
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1132 Byte
Status CE

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:62:30: error: no matching function for call to ‘max(ll, int)’
     cout << max(dfs(x-1)-2, 0) << endl;
                              ^
In file included from /usr/include/c++/5/bits/char_traits.h:39:0,
                 from /usr/include/c++/5/ios:40,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from ./Main.cpp:1:
/usr/include/c++/5/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^
/usr/include/c++/5/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
./Main.cpp:62:30: note:   deduced conflicting types for parameter ‘const _Tp’ (‘long long int’ and ‘int’)
     cout << max(dfs(x-1)-2, 0) << endl;
                              ^
In file included from /usr/include/c++/5/bits/char_traits.h:39:0,
                 from /usr/include/c++/5/ios:40...