# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
658949 |
2022-11-15T14:55:13 Z |
Soul234 |
Museum (CEOI17_museum) |
C++14 |
|
374 ms |
1048576 KB |
#include<bits/stdc++.h>
using namespace std;
void DBG() { cerr << "]\n"; }
template<class H, class... T> void DBG(H h, T... t) {
cerr << h; if(sizeof...(t)) cerr << ", ";
DBG(t...);
}
#ifdef LOCAL
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif // LOCAL
#define FOR(i,a,b) for(int i = (a) ; i<(b) ; i++)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for(int i = (b)-1 ; i>=(a) ; i--)
#define R0F(i,a) ROF(i,0,a)
#define each(e,a) for(auto &e : (a))
#define sz(v) (int)(v).size()
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb push_back
#define tcT template<class T
#define nl "\n"
#define fi first
#define se second
using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
using str = string;
using db = long double;
tcT> using V = vector<T>;
tcT> using pqg = priority_queue<T,vector<T>,greater<T>>;
void setIO(string NAME = "") {
cin.tie(0)->sync_with_stdio(0);
if(sz(NAME)) {
freopen((NAME + ".inp").c_str(),"r",stdin);
freopen((NAME + ".out").c_str(),"w",stdout);
}
}
tcT> bool ckmin(T&a, const T&b) {
return b < a ? a=b,1 : 0; }
tcT> bool ckmax(T&a, const T&b) {
return b > a ? a=b,1 : 0; }
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int MX = 1e4+2;
int N, K, X;
ll dp[2][MX][MX];
int sz[MX];
V<pi> adj[MX];
void dfs(int u, int p) {
sz[u] = 1;
F0R(i, 2) dp[i][u][0] = dp[i][u][1] = 0;
each(ed, adj[u]) if(ed.fi != p) {
int v = ed.fi, c = ed.se;
dfs(v, u);
R0F(i, sz[u]+1) {
ROF(j,1,sz[v]+1) {
ckmin(dp[0][u][i+j], dp[0][u][i] + 2LL*c + dp[0][v][j]);
ckmin(dp[1][u][i+j], dp[0][u][i] + dp[1][v][j] + 1LL*c);
ckmin(dp[1][u][i+j], dp[1][u][i] + 2LL*c + dp[0][v][j]);
}
}
sz[u] += sz[v];
}
}
void solve() {
cin >> N >> K >> X;
F0R(i, N-1) {
int u, v, c;
cin >> u >> v >> c;
adj[u].pb({v, c});
adj[v].pb({u, c});
}
memset(dp, 0x3f, sizeof dp);
dfs(X, -1);
cout << dp[1][X][K] << nl;
}
int main() {
setIO();
int t=1;
//cin>>t;
while(t-->0) {
solve();
}
return 0;
}
Compilation message
museum.cpp: In function 'void setIO(std::string)':
museum.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | freopen((NAME + ".inp").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
museum.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | freopen((NAME + ".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
356 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
374 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
374 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
356 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |