Submission #658950

# Submission time Handle Problem Language Result Execution time Memory
658950 2022-11-15T14:56:19 Z Soul234 Museum (CEOI17_museum) C++14
Compilation error
0 ms 0 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;

int 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 dfs(int, int)':
museum.cpp:70:71: error: no matching function for call to 'ckmin(int&, long long int)'
   70 |                 ckmin(dp[0][u][i+j], dp[0][u][i] + 2LL*c + dp[0][v][j]);
      |                                                                       ^
museum.cpp:45:11: note: candidate: 'template<class T> bool ckmin(T&, const T&)'
   45 | tcT> bool ckmin(T&a, const T&b) {
      |           ^~~~~
museum.cpp:45:11: note:   template argument deduction/substitution failed:
museum.cpp:70:71: note:   deduced conflicting types for parameter 'const T' ('int' and 'long long int')
   70 |                 ckmin(dp[0][u][i+j], dp[0][u][i] + 2LL*c + dp[0][v][j]);
      |                                                                       ^
museum.cpp:71:71: error: no matching function for call to 'ckmin(int&, long long int)'
   71 |                 ckmin(dp[1][u][i+j], dp[0][u][i] + dp[1][v][j] + 1LL*c);
      |                                                                       ^
museum.cpp:45:11: note: candidate: 'template<class T> bool ckmin(T&, const T&)'
   45 | tcT> bool ckmin(T&a, const T&b) {
      |           ^~~~~
museum.cpp:45:11: note:   template argument deduction/substitution failed:
museum.cpp:71:71: note:   deduced conflicting types for parameter 'const T' ('int' and 'long long int')
   71 |                 ckmin(dp[1][u][i+j], dp[0][u][i] + dp[1][v][j] + 1LL*c);
      |                                                                       ^
museum.cpp:72:71: error: no matching function for call to 'ckmin(int&, long long int)'
   72 |                 ckmin(dp[1][u][i+j], dp[1][u][i] + 2LL*c + dp[0][v][j]);
      |                                                                       ^
museum.cpp:45:11: note: candidate: 'template<class T> bool ckmin(T&, const T&)'
   45 | tcT> bool ckmin(T&a, const T&b) {
      |           ^~~~~
museum.cpp:45:11: note:   template argument deduction/substitution failed:
museum.cpp:72:71: note:   deduced conflicting types for parameter 'const T' ('int' and 'long long int')
   72 |                 ckmin(dp[1][u][i+j], dp[1][u][i] + 2LL*c + dp[0][v][j]);
      |                                                                       ^
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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~