Submission #1262600

#TimeUsernameProblemLanguageResultExecution timeMemory
1262600vestonvestonMuseum (CEOI17_museum)C++20
100 / 100
461 ms784504 KiB
#include <bits/stdc++.h> #define name "vestonluvto" const char* namein = name ".inp"; const char* nameout = name ".out"; #define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define mod ((1ll) << 31) - 1; #define mod1 ((1ll) << 61) - 1; #define PI 3.141592653589793238462 #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() using namespace std; #ifndef LOCAL #define debug(x) cerr << #x <<" "; _print(x); cerr << endl; #else #define debug(x) #endif void _print(int t) {cerr << t;} void _print(long long t) {cerr << t;} void _print(string t) {cerr << t;} void _print(char t) {cerr << t;} void _print(long double t) {cerr << t;} void _print(double t) {cerr << t;} void _print(unsigned long long t) {cerr << t;} template <class T, class V> void _print(pair <T, V> p); template <class T> void _print(vector <T> v); template <class T> void _print(set <T> v); template <class T, class V> void _print(map <T, V> v); template <class T> void _print(multiset <T> v); template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} void homefix(){ #ifndef LOCAL freopen("fixcode.txt", "w", stderr); #endif } void home(){ homefix(); if (fopen(namein, "r")) { freopen(namein, "r", stdin); freopen(nameout, "w", stdout); } } int n, k, x; vector<pair<int, int> > dt[10004]; void nhap(){ cin >> n >> k >> x; for(int i = 1; i < n; i++){ int u, v; long long w; cin >> u >> v >> w; dt[u].push_back({w, v}); dt[v].push_back({w, u}); } } int dp[10004][10004][2]; int sub[10004]; void dfs(int u, int par){ dp[u][1][0] = dp[u][1][1] = 0; sub[u] = 1; for(auto &v : dt[u])if(v.second != par){ dfs(v.second, u); for(int i = sub[u]; i >= 1; i--){ for(int j = sub[v.second]; j >= 1; j--){ dp[u][i+j][0] = min(dp[u][i+j][0], dp[u][i][0] + dp[v.second][j][0] + 2*v.first); dp[u][i+j][1] = min(dp[u][i+j][1], min(dp[u][i][0] + dp[v.second][j][1] + v.first, dp[u][i][1] + dp[v.second][j][0] + 2*v.first)); } } sub[u] += sub[v.second]; } } void bfsolve(){ for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++)dp[i][j][0] = dp[i][j][1] = 1e18; } dfs(x, 0); } void solve(){bfsolve(); cout << min(dp[x][k][1], dp[x][k][0]); } int main(){ fastio(); home();int t = 1; //cin >> t; while(t--)nhap(), solve(); return 0; } /* ___________ ╔══╗ ▐▀▄ ▄▀▌ ▄▄▄▄▄▄▄ / \ ╚╗╔╝ ▌▒▒▀▄▄▄▄▄▀▒▒▐▄▀▀▒██▒██▒▀▀ / MEO \ ╔╝(¯’v´¯) ▐▒▒▒▒▀▒▀▒▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▀▄ \ ╚══’.¸. ▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄▒▒▒▒▒▒▒▒▒▒▒▒▀▄ \ __________ / ╔♫═╗╔╗ kitten ▀█▒▒▒█▌▒▒█▒▒▐█▒▒▒▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▌ |/ ╚╗╔╝║║♫═╦╦╦╔╗ ▀▌▒▒▒▒▒▒▀▒▀▒▒▒▒▒▒▀▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐ ▄▄ ╔╝╚╗♫╚╣║║║║╔╣ ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▌▄█▒█ ╚═♫╝╚═╩═╩♫╩═╝ ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒█▀ ┊  ┊  ┊  ┊ ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▀ ┊  ┊  ┊  ┊ ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▌ ┊  ┊  ┊  ★ ▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐ ┊  ┊  ☆ ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▌ ┊  ★ ▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐ ☆ ▐▄▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄▌ ▀▄▄▀▀▀▀▀▄▄▀▀▀▀▀▀▀▄▄▀▀▀▀▀▄▄▀ */

Compilation message (stderr)

museum.cpp: In function 'void bfsolve()':
museum.cpp:88:64: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   88 |         for(int j = 1; j <= n; j++)dp[i][j][0] = dp[i][j][1] = 1e18;
      |                                                                ^~~~
museum.cpp: In function 'void homefix()':
museum.cpp:43:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         freopen("fixcode.txt", "w", stderr);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
museum.cpp: In function 'void home()':
museum.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         freopen(namein, "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
museum.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen(nameout, "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...