Submission #564329

# Submission time Handle Problem Language Result Execution time Memory
564329 2022-05-19T01:53:08 Z minhcool Road Closures (APIO21_roads) C++17
24 / 100
2000 ms 20148 KB
#include "roads.h"
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fi first
#define se second
#define pb push_back
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int N = 1e5 + 5, oo = 1e18 + 7, mod = 1e9 + 7;
 
ll n;
 
vector<ii> Adj[N];
 
ll k;
ll dp[N][2];
 
void dfs(int u, int p){
	int we = 0;
	for(auto it : Adj[u]){
		int v = it.fi;
		if(v == p){
			we = it.se;
			continue;
		}
		dfs(v, u);
	}
	vector<ll> vc;
	ll sum = 0;
	for(auto it : Adj[u]){
		int v = it.fi;
		if(v == p) continue;
		sum += dp[v][0];
		vc.pb(dp[v][0] - dp[v][1]);
	}
	sort(vc.begin(), vc.end());
	reverse(vc.begin(), vc.end());
	ll sum2 = 0;
	for(int i = 0; i < min((ll)vc.size(), (ll)k - 1); i++){
		sum2 += max(0LL, vc[i]);
	}
	dp[u][0] = sum - sum2 - (((ll)vc.size() < k || !k) ? 0 : max(0LL, vc[k - 1])) + we;
	dp[u][1] = sum - sum2;
	//cout << u << " " << dp[u][0] << " " << dp[u][1] << "\n";
}
 
vector<long long> minimum_closure_costs(int N, vector<int> U, vector<int> V, vector<int> W){
	n = N;
	//cout << U.size() << " " << V.size() << " " << W.size() << "\n";
	//exit(0);
	for(int i = 0; i < (n - 1); i++){
		U[i]++, V[i]++;
		Adj[U[i]].pb({V[i], W[i]});
		Adj[V[i]].pb({U[i], W[i]});
	}
	vector<ll> ans;
	for(int i = 0; i < n; i++){
		k = i;
		dfs(1, 1);
		ans.pb(min(dp[1][0], dp[1][1]));		
	}
	return ans;
}
 
/*

void process(){
	int n;
	vector<int> a, b, c;
	cin >> n;
	for(int i = 1; i <= 3 * n - 3; i++){
		int x;
		cin >> x;
		if(i <= (n - 1)) a.pb(x);
		else if(i <= 2 * (n - 1)) b.pb(x);
		else c.pb(x);
	}
	vector<long long> temp = minimum_closure_costs(n, a, b, c);
	for(auto it : temp) cout << it << " ";
}
 
signed main(){
	ios_base::sync_with_stdio(0);
	freopen("roads.inp", "r", stdin);
	freopen("roads.out", "w", stdout);
	process();
}*/

Compilation message

roads.cpp:14:34: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   14 | const int N = 1e5 + 5, oo = 1e18 + 7, mod = 1e9 + 7;
      |                             ~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 170 ms 2828 KB Output is correct
3 Correct 176 ms 2872 KB Output is correct
4 Correct 77 ms 2872 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 3 ms 2656 KB Output is correct
7 Correct 3 ms 2644 KB Output is correct
8 Correct 81 ms 2824 KB Output is correct
9 Correct 119 ms 2856 KB Output is correct
10 Correct 2 ms 2660 KB Output is correct
11 Correct 3 ms 2644 KB Output is correct
12 Execution timed out 2061 ms 9108 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Execution timed out 2100 ms 20148 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 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 6 ms 2568 KB Output is correct
6 Correct 3 ms 2656 KB Output is correct
7 Correct 5 ms 2644 KB Output is correct
8 Correct 4 ms 2644 KB Output is correct
9 Correct 4 ms 2624 KB Output is correct
10 Correct 4 ms 2656 KB Output is correct
11 Correct 3 ms 2644 KB Output is correct
12 Correct 3 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 3 ms 2644 KB Output is correct
15 Correct 3 ms 2652 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 4 ms 2644 KB Output is correct
18 Correct 4 ms 2660 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 3 ms 2656 KB Output is correct
21 Correct 3 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 6 ms 2568 KB Output is correct
6 Correct 3 ms 2656 KB Output is correct
7 Correct 5 ms 2644 KB Output is correct
8 Correct 4 ms 2644 KB Output is correct
9 Correct 4 ms 2624 KB Output is correct
10 Correct 4 ms 2656 KB Output is correct
11 Correct 3 ms 2644 KB Output is correct
12 Correct 3 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 3 ms 2644 KB Output is correct
15 Correct 3 ms 2652 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 4 ms 2644 KB Output is correct
18 Correct 4 ms 2660 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 3 ms 2656 KB Output is correct
21 Correct 3 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 108 ms 2776 KB Output is correct
24 Correct 241 ms 2876 KB Output is correct
25 Correct 193 ms 2932 KB Output is correct
26 Correct 173 ms 2852 KB Output is correct
27 Correct 146 ms 2856 KB Output is correct
28 Correct 80 ms 2852 KB Output is correct
29 Correct 214 ms 2844 KB Output is correct
30 Correct 137 ms 2872 KB Output is correct
31 Correct 127 ms 2876 KB Output is correct
32 Correct 84 ms 2892 KB Output is correct
33 Correct 122 ms 3056 KB Output is correct
34 Correct 151 ms 3124 KB Output is correct
35 Correct 122 ms 3080 KB Output is correct
36 Correct 189 ms 2860 KB Output is correct
37 Correct 187 ms 2872 KB Output is correct
38 Correct 84 ms 2876 KB Output is correct
39 Correct 2 ms 2644 KB Output is correct
40 Correct 2 ms 2772 KB Output is correct
41 Correct 3 ms 2644 KB Output is correct
42 Correct 4 ms 2644 KB Output is correct
43 Correct 3 ms 2644 KB Output is correct
44 Correct 4 ms 2656 KB Output is correct
45 Correct 4 ms 2656 KB Output is correct
46 Correct 4 ms 2656 KB Output is correct
47 Correct 3 ms 2644 KB Output is correct
48 Correct 3 ms 2652 KB Output is correct
49 Correct 3 ms 2644 KB Output is correct
50 Correct 2 ms 2652 KB Output is correct
51 Correct 3 ms 2644 KB Output is correct
52 Correct 3 ms 2660 KB Output is correct
53 Correct 143 ms 2816 KB Output is correct
54 Correct 270 ms 2852 KB Output is correct
55 Correct 125 ms 2984 KB Output is correct
56 Correct 91 ms 3020 KB Output is correct
57 Correct 115 ms 2864 KB Output is correct
58 Correct 2 ms 2644 KB Output is correct
59 Correct 4 ms 2644 KB Output is correct
60 Correct 4 ms 2644 KB Output is correct
61 Correct 2 ms 2644 KB Output is correct
62 Correct 3 ms 2644 KB Output is correct
63 Correct 2 ms 2644 KB Output is correct
64 Correct 252 ms 2832 KB Output is correct
65 Correct 239 ms 2852 KB Output is correct
66 Correct 101 ms 2848 KB Output is correct
67 Correct 98 ms 2848 KB Output is correct
68 Correct 93 ms 2848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2091 ms 10080 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2091 ms 10080 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 170 ms 2828 KB Output is correct
3 Correct 176 ms 2872 KB Output is correct
4 Correct 77 ms 2872 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 3 ms 2656 KB Output is correct
7 Correct 3 ms 2644 KB Output is correct
8 Correct 81 ms 2824 KB Output is correct
9 Correct 119 ms 2856 KB Output is correct
10 Correct 2 ms 2660 KB Output is correct
11 Correct 3 ms 2644 KB Output is correct
12 Execution timed out 2061 ms 9108 KB Time limit exceeded
13 Halted 0 ms 0 KB -