Submission #980356

# Submission time Handle Problem Language Result Execution time Memory
980356 2024-05-12T06:00:26 Z hqminhuwu Museum (CEOI17_museum) C++14
0 / 100
68 ms 6356 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll,ll> pll;
typedef pair <ll,ll> pii;
typedef pair <ll,pii> piii;

#define forr(_a,_b,_c) for(ll _a = (_b); _a <= (_c); ++_a)
#define ford(_a,_b,_c) for(ll _a = (_b) + 1; _a --> (_c);)
#define forf(_a,_b,_c) for(ll _a = (_b); _a < (_c); ++_a)
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define mask(i) (1LL << (i))
#define bit(x, i) (((x) >> (i)) & 1)
#define bp __builtin_popcountll
#define file "test"

const ll N = 1e4 + 5;
const ll oo = 1e16;
const ll mod = 1e9 + 7; // 998244353;

void minz (ll &u, ll v){
	if (u > v)
		u = v;
}

vector <ll> dp[N][2];
vector <pii> a[N];


void dfs (ll u, ll p){
	dp[u][0].pb(0);
	dp[u][1].pb(0);

	for (pii t : a[u]){
		ll v = t.st, w = t.nd;
		if (v == p) continue;
		dfs(v, u);
		ll lmt = dp[u][0].size();
		forf (i, 0, dp[v][0].size()){
			dp[u][0].pb(oo);
			dp[u][1].pb(oo);
		}

		ford (i, lmt, 0){
			forf (j, 0, dp[v][0].size()){
			//	cout << i << " " << j << " " << i + j + 1 << "\n";
				minz(dp[u][0][i + j + 1], dp[u][0][i] + dp[v][0][j] + 2 * w);
				minz(dp[u][1][i + j + 1], dp[u][0][i] + dp[v][1][j] + w);
			}
		}
	}
}

ll n, k, root, u, v, w;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	#ifdef hqm
		freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
	#endif

	cin >> n >> k >> root;

	forf (i, 1, n){
		cin >> u >> v >> w;
		a[u].pb({v, w});
		a[v].pb({u, w});
	}

	dfs(root, root);

	cout << dp[root][1][k - 1];

	return 0;
}
/*



*/

Compilation message

museum.cpp: In function 'void dfs(ll, ll)':
museum.cpp:11:45: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 | #define forf(_a,_b,_c) for(ll _a = (_b); _a < (_c); ++_a)
      |                                             ^
museum.cpp:44:3: note: in expansion of macro 'forf'
   44 |   forf (i, 0, dp[v][0].size()){
      |   ^~~~
museum.cpp:11:45: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 | #define forf(_a,_b,_c) for(ll _a = (_b); _a < (_c); ++_a)
      |                                             ^
museum.cpp:50:4: note: in expansion of macro 'forf'
   50 |    forf (j, 0, dp[v][0].size()){
      |    ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 68 ms 6356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 68 ms 6356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1116 KB Output isn't correct
2 Halted 0 ms 0 KB -