Submission #319342

# Submission time Handle Problem Language Result Execution time Memory
319342 2020-11-05T01:16:14 Z caoash Dostavljač (COCI18_dostavljac) C++14
14 / 140
2000 ms 5100 KB
#include <bits/stdc++.h> 
using namespace std;

using ll = long long;

using vi = vector<int>;
using vl = vector<ll>;
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define lb lower_bound
#define ub upper_bound

using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair

const int MX = 200005;
const int MOD = (int) (1e9 + 7);
const ll INF = (ll) 1e18;

int n, m;
vi adj[MX];
int a[MX];
int ans = 0;

void solve(int v, int x, int d, int mask) {
    if (x > m) return;
    ans = max(ans, d);
    for (int to : adj[v]) {
        solve(to, x + 1, d, mask); 
    }
    if (!(mask & (1 << v))) solve(v, x + 1, d + a[v], mask | (1 << v));
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n - 1; i++) {
        int u, v; cin >> u >> v;
        u--, v--;
        adj[u].pb(v), adj[v].pb(u);
    }
    solve(0, 0, 0, 0);
    cout << ans << '\n';
}

# Verdict Execution time Memory Grader output
1 Correct 7 ms 4972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2083 ms 4972 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 2091 ms 5100 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 2083 ms 4972 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 2079 ms 5100 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2055 ms 5100 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2079 ms 5100 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2083 ms 5100 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2085 ms 5100 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2029 ms 5100 KB Time limit exceeded
2 Halted 0 ms 0 KB -