Submission #824601

# Submission time Handle Problem Language Result Execution time Memory
824601 2023-08-14T08:10:41 Z Hanksburger Road Closures (APIO21_roads) C++17
21 / 100
2000 ms 36280 KB
#include "roads.h"
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > adj[100005];
long long dp[100005][2], deg[100005], limit;
vector<long long> ans;
void dfs(long long u, long long p, long long x)
{
    for (long long i=0; i<adj[u].size(); i++)
    {
        long long v=adj[u][i].first, w=adj[u][i].second;
        if (v==p)
            continue;
        dfs(v, u, w);
    }
    vector<long long> vec, tmp;
    vec.push_back(0);
    for (long long i=1; i<=limit; i++)
        vec.push_back(1e18);
    for (long long i=0; i<adj[u].size(); i++)
    {
        long long v=adj[u][i].first, w=adj[u][i].second;
        if (v==p)
            continue;
        tmp.push_back(vec[0]+dp[v][0]);
        for (int j=1; j<=limit; j++)
            tmp.push_back(min(vec[j]+dp[v][0], vec[j-1]+dp[v][1]));
        vec=tmp;
        tmp.clear();
    }
    long long mn=1e18;
    for (long long i=0; i<limit; i++)
        mn=min(mn, vec[i]);
    dp[u][0]=min(mn, vec[limit])+x;
    dp[u][1]=mn;
}
vector<long long> minimum_closure_costs(int n, vector<int> u, vector<int> v, vector<int> w)
{
    for (long long i=0; i<n-1; i++)
    {
        adj[u[i]].push_back({v[i], w[i]});
        adj[v[i]].push_back({u[i], w[i]});
        deg[u[i]]++, deg[v[i]]++;
    }
    long long mx=0;
    for (long long i=0; i<n; i++)
        mx=max(mx, deg[i]);
    for (long long i=0; i<mx; i++)
    {
        limit=i;
        dfs(0, 0, 0);
        ans.push_back(dp[0][0]);
    }
    for (long long i=mx; i<n; i++)
        ans.push_back(0);
    return ans;
}

Compilation message

roads.cpp: In function 'void dfs(long long int, long long int, long long int)':
roads.cpp:9:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     for (long long i=0; i<adj[u].size(); i++)
      |                         ~^~~~~~~~~~~~~~
roads.cpp:20:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for (long long i=0; i<adj[u].size(); i++)
      |                         ~^~~~~~~~~~~~~~
roads.cpp:22:38: warning: unused variable 'w' [-Wunused-variable]
   22 |         long long v=adj[u][i].first, w=adj[u][i].second;
      |                                      ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Execution timed out 2070 ms 2844 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 69 ms 28848 KB Output is correct
3 Correct 65 ms 34000 KB Output is correct
4 Correct 67 ms 36200 KB Output is correct
5 Correct 85 ms 36280 KB Output is correct
6 Correct 3 ms 3204 KB Output is correct
7 Correct 3 ms 3284 KB Output is correct
8 Correct 3 ms 3156 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 47 ms 22308 KB Output is correct
13 Correct 89 ms 35408 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 59 ms 32108 KB Output is correct
16 Correct 83 ms 35344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 3 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 3 ms 2644 KB Output is correct
13 Correct 18 ms 2676 KB Output is correct
14 Correct 24 ms 2684 KB Output is correct
15 Correct 36 ms 2684 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 3 ms 2644 KB Output is correct
18 Correct 4 ms 2644 KB Output is correct
19 Correct 18 ms 2684 KB Output is correct
20 Correct 21 ms 2684 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 3 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 3 ms 2644 KB Output is correct
13 Correct 18 ms 2676 KB Output is correct
14 Correct 24 ms 2684 KB Output is correct
15 Correct 36 ms 2684 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 3 ms 2644 KB Output is correct
18 Correct 4 ms 2644 KB Output is correct
19 Correct 18 ms 2684 KB Output is correct
20 Correct 21 ms 2684 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 3 ms 2644 KB Output is correct
23 Correct 4 ms 2772 KB Output is correct
24 Correct 4 ms 2900 KB Output is correct
25 Correct 4 ms 2820 KB Output is correct
26 Correct 42 ms 2884 KB Output is correct
27 Correct 471 ms 2908 KB Output is correct
28 Correct 554 ms 2888 KB Output is correct
29 Correct 5 ms 2900 KB Output is correct
30 Correct 22 ms 2900 KB Output is correct
31 Correct 31 ms 2900 KB Output is correct
32 Execution timed out 2061 ms 2888 KB Time limit exceeded
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 333 ms 14080 KB Output is correct
2 Correct 236 ms 15168 KB Output is correct
3 Execution timed out 2056 ms 14312 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 333 ms 14080 KB Output is correct
2 Correct 236 ms 15168 KB Output is correct
3 Execution timed out 2056 ms 14312 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Execution timed out 2070 ms 2844 KB Time limit exceeded
3 Halted 0 ms 0 KB -