Submission #831989

# Submission time Handle Problem Language Result Execution time Memory
831989 2023-08-20T19:20:42 Z Antekb Road Closures (APIO21_roads) C++17
0 / 100
2000 ms 24724 KB
#include<bits/stdc++.h>
#include "roads.h"
#define st first
#define nd second
#define pb push_back
#define pp pop_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
using namespace std;

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

void debug(){cerr<<"\n";}
template <typename H, typename... T>
void debug(H h, T... t) {cerr<<h; if (sizeof...(t)) cerr << ", "; debug(t...);}
#define deb(x...) cerr<<#x<<" = ";debug(x);

const int N=1e5+5;
vii E[N];
vector<ll> dp[N];

void dfs(int v, int p){
	dp[v].resize(E[v].size()+1+(p==-1));
	for(pii e:E[v]){
		int u=e.st, c=e.nd;
		if(u!=p){
			dfs(u, v);
			dp[v].resize(max(dp[v].size(), dp[u].size()));
		}
	}
	for(int i=1; i<dp[v].size(); i++){
		vector<int> V;
		for(pii e:E[v]){
			int u=e.st, c=e.nd;
			if(u!=p){
				if(i<dp[u].size()){
					dp[v][i]+=dp[u][i];
					V.pb(dp[u][i-1]+c-dp[u][i]);
				}
				else{
					dp[v][i]+=dp[u].back();
					V.pb(c);
				}
			}
		}
		sort(all(V));
		for(int j=V.size()-1; j>=int(V.size())-i && j>=0 && V[j]>=0; j--){
			dp[v][i]+=V[j];
		}
	}
}

std::vector<long long> minimum_closure_costs(int n, std::vector<int> uu, 
	std::vector<int> vv,std::vector<int> ww) {
	ll sum=0;
	for(int i=0; i<n-1; i++){
		E[uu[i]].eb(vv[i], ww[i]);
		E[vv[i]].eb(uu[i], ww[i]);
		sum+=ww[i];
	}
	dfs(0, -1);
	vector<ll> ans=dp[0];
	ans.resize(n, ans.back());
	for(ll &i:ans){
		i=sum-i;
	}
	return ans;
}

Compilation message

roads.cpp: In function 'void dfs(int, int)':
roads.cpp:29:15: warning: unused variable 'c' [-Wunused-variable]
   29 |   int u=e.st, c=e.nd;
      |               ^
roads.cpp:35:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |  for(int i=1; i<dp[v].size(); i++){
      |               ~^~~~~~~~~~~~~
roads.cpp:40:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     if(i<dp[u].size()){
      |        ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 121 ms 5204 KB Output is correct
3 Correct 154 ms 5204 KB Output is correct
4 Correct 40 ms 5208 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 36 ms 5168 KB Output is correct
9 Correct 61 ms 5204 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Execution timed out 2063 ms 11876 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Incorrect 48 ms 24724 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Incorrect 3 ms 4948 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Incorrect 3 ms 4948 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 73 ms 15872 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 73 ms 15872 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 121 ms 5204 KB Output is correct
3 Correct 154 ms 5204 KB Output is correct
4 Correct 40 ms 5208 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 36 ms 5168 KB Output is correct
9 Correct 61 ms 5204 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Execution timed out 2063 ms 11876 KB Time limit exceeded
13 Halted 0 ms 0 KB -