제출 #1257074

#제출 시각아이디문제언어결과실행 시간메모리
1257074_dtq_Museum (CEOI17_museum)C++20
20 / 100
3119 ms784268 KiB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define sz(x) (ll)(x.size())
#define all(v) v.begin(), v.end()
#define se second
#define fi first
using namespace std;

const int N = 1e4 + 2;
const int INF = 1e9;

int n, i, k, x, u, v, w, dp[N][N][2], sz[N];

vector<pair<int, int>>vec[N];

void calc( ll x, ll root )
{
    sz[x] = 1;

    dp[x][1][1] = dp[x][1][0] = 0;

    for(auto k : vec[x])
    {
        if(k.fi != root){ calc(k.fi, x);

        sz[x] += sz[k.fi];
        for( int i = sz[x]; i >= 1; i -- )
        {
            for( int j = sz[k.fi]; j >= 1; j -- )
            {
                if(i <= j) continue;

                dp[x][i][0] = min(dp[x][i][0], dp[x][i - j][0] + dp[k.fi][j][1] + 2 * k.se);
                dp[x][i][0] = min(dp[x][i][0], dp[x][i - j][1] + dp[k.fi][j][0] + k.se);
                dp[x][i][1] = min(dp[x][i][1], dp[x][i - j][1] + dp[k.fi][j][1] + 2 * k.se);
            }
        }

    }
    }
}
int main()
{
#define TN "d"
    if(fopen(TN ".in", "r"))
    {
        freopen(TN ".in", "r", stdin);
        freopen(TN ".out", "w", stdout);
    }
    cin.tie(0)->sync_with_stdio(0);

    cin >> n >> k >> x;

    for( i = 1; i < n; i ++ )
    {
        cin >> u >> v >> w;

        vec[u].pb({v, w});
        vec[v].pb({u, w});
    }

    for( i = 1; i <= n; i ++ )
        for(int j = 1; j <= n; j ++ ) dp[i][j][0] = dp[i][j][1] = INF;

    calc(x, 0);

    cout << dp[x][k][0];

    return 0;
}
/*
*/

컴파일 시 표준 에러 (stderr) 메시지

museum.cpp: In function 'int main()':
museum.cpp:48:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         freopen(TN ".in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
museum.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         freopen(TN ".out", "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...