Submission #723215

# Submission time Handle Problem Language Result Execution time Memory
723215 2023-04-13T10:52:14 Z grossly_overconfident Road Closures (APIO21_roads) C++17
14 / 100
2000 ms 1048576 KB
//#include "roads.h"
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
//#define int long long
//#define INT_MAX LONG_LONG_MAX

long long findscore(multiset<pair<long long, pair<long long, long long>>>& candidates, int k, int j){
    long long score = 0;
    
    for (auto i : candidates){
        
        if (j <= k){
            score += min(i.second.first, i.second.second);
        }
        else{
            j--;
            score += i.second.second;
        }

       
    }
    return score;
}

long long solve(vector<vector<long long>>& dp, vector<vector<pair<int, int>>>& adj, int p, int n, int k, int i, int j){
    if (dp[i][j] != -1){
        return dp[i][j];
    }
    bool ac = true;
    multiset<pair<long long, pair<long long, long long>>> candidates;
    for (auto a : adj[i]){
        if (a.first != p){
            ac = false;
            long long op1 = solve(dp, adj, i, n, k, a.first, adj[a.first].size());
            long long op2 = solve(dp, adj, i, n, k, a.first, adj[a.first].size() - 1) + a.second;
            candidates.insert({op2 - op1, {op1, op2}});
        }
    }
    if (ac){
        return 0;
    }
    return dp[i][j] = findscore(candidates, k, j);
}

vector<long long> minimum_closure_costs(int n, vector<int> u, vector<int> v, vector<int> w){
    vector<long long> out(n);
    vector<vector<pair<int, int>>> adj(n);
    for (int i = 0; i < n - 1; ++i){
        adj[u[i]].push_back({v[i], w[i]});
        adj[v[i]].push_back({u[i], w[i]});
    }
    /*
    int leaf = 0;
    
    for (int i = 0; i < n; ++i){
        if (adj[i].size() == 1){
            leaf = i;
            break;
        }
    }
    */
    for (int i = 0; i < n; ++i){
        
        vector<vector<long long>> dp(n + 10, vector<long long>(n + 10, -1));
        out[i] = solve(dp, adj, -1, n, i, 0, adj[0].size());
    }
    
    return out;
}
/*
int main(){
    int n;
    cin >> n;
    vector<int> u(n - 1), v(n - 1), w(n - 1);
    for (int i = 0; i < n - 1; ++i){
        cin >> u[i];
    }
    for (int i = 0; i < n - 1; ++i){
        cin >> v[i];
    }
    for (int i = 0; i < n - 1; ++i){
        cin >> w[i];
    }
    vector<long long> out;
    out = minimum_closure_costs(n, u, v, w);
    for (auto a : out){
        cout << a << " ";
    }
    return 0;
}
*/

# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Execution timed out 2059 ms 28604 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Runtime error 417 ms 1048576 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 9 ms 520 KB Output is correct
5 Correct 24 ms 676 KB Output is correct
6 Correct 23 ms 644 KB Output is correct
7 Correct 17 ms 604 KB Output is correct
8 Correct 25 ms 680 KB Output is correct
9 Correct 24 ms 676 KB Output is correct
10 Correct 13 ms 620 KB Output is correct
11 Correct 18 ms 676 KB Output is correct
12 Correct 22 ms 716 KB Output is correct
13 Correct 6 ms 428 KB Output is correct
14 Correct 11 ms 596 KB Output is correct
15 Correct 13 ms 688 KB Output is correct
16 Correct 4 ms 340 KB Output is correct
17 Correct 31 ms 680 KB Output is correct
18 Correct 28 ms 668 KB Output is correct
19 Correct 13 ms 644 KB Output is correct
20 Correct 15 ms 596 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 9 ms 520 KB Output is correct
5 Correct 24 ms 676 KB Output is correct
6 Correct 23 ms 644 KB Output is correct
7 Correct 17 ms 604 KB Output is correct
8 Correct 25 ms 680 KB Output is correct
9 Correct 24 ms 676 KB Output is correct
10 Correct 13 ms 620 KB Output is correct
11 Correct 18 ms 676 KB Output is correct
12 Correct 22 ms 716 KB Output is correct
13 Correct 6 ms 428 KB Output is correct
14 Correct 11 ms 596 KB Output is correct
15 Correct 13 ms 688 KB Output is correct
16 Correct 4 ms 340 KB Output is correct
17 Correct 31 ms 680 KB Output is correct
18 Correct 28 ms 668 KB Output is correct
19 Correct 13 ms 644 KB Output is correct
20 Correct 15 ms 596 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Execution timed out 2093 ms 12712 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 403 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 403 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Execution timed out 2059 ms 28604 KB Time limit exceeded
3 Halted 0 ms 0 KB -