Submission #239822

# Submission time Handle Problem Language Result Execution time Memory
239822 2020-06-17T10:53:32 Z Vimmer Dostavljač (COCI18_dostavljac) C++14
0 / 140
141 ms 2296 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")

#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 101001
#define M ll(1e9 + 7)
#define inf 1e9 + 1e9


using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef short int si;
typedef array <int, 3> a3;

//typedef tree <int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


int n, m;

ll f[505][505], a[505], ans;

vector <int> g[505];

void dfs(int v, int glub, int p)
{
    f[v][glub + 1] = a[v];

    for (auto it : g[v])
    {
        if (it == p) continue;

        dfs(it, glub + 1, v);

        for (int i = m; i >= glub; i--)
            for (int j = 0; j + i - glub <= m; j++)
                {
                    ans = max(ans, f[v][i] + f[it][j]);

                    if (j + i - glub + 1 <= m) f[v][j + i - glub + 1]  = max(f[v][j + i - glub + 1], f[it][j] + f[v][i]);
                }
    }
}

int main()
{
    //freopen("input.txt", "r", stdin); //freopen("output4.txt", "w", stdout);

    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> m;

    for (int i = 1; i <= n; i++) cin >> a[i];

    for (int i = 1; i < n; i++)
    {
        int x, y;

        cin >> x >> y;

        g[x].pb(y);

        g[y].pb(x);
    }

    dfs(1, 0, -1);


    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 512 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 640 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 640 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 1152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 1144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 1580 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 77 ms 1912 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 141 ms 2296 KB Output isn't correct
2 Halted 0 ms 0 KB -