QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#60166#2161. The Cost of Speed LimitsMIT01#WA 3ms6044kbC++232.1kb2022-11-03 10:15:552022-11-03 10:15:56

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-03 10:15:56]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:6044kb
  • [2022-11-03 10:15:55]
  • 提交

answer

using namespace std;
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define vi vector<int>
#define pi pair<int, int>
#define maxn 20005
#define mod 998244353
template<typename T> bool chkmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chkmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
ll ksm(ll a, ll b) {if (b == 0) return 1; ll ns = ksm(a, b >> 1); ns = ns * ns % mod; if (b & 1) ns = ns * a % mod; return ns;}
using namespace std;
#define ui unsigned int
int n, c;
ui dp[maxn][maxn], bst[maxn];
vector<pi> eg[maxn];
vi tr;
int fl[maxn];
int fa[maxn];
void dfs1(int a) {
    for (auto v: eg[a]) {
        if (v.fi == fa[a]) continue;
        fa[v.fi] = a;
        fl[v.fi] = lower_bound(tr.begin(), tr.end(), v.se) - tr.begin();
        dfs1(v.fi);
    }
}
const ui inf = 4e9;
void dfs2(int a) {
    for (auto [v, d] : eg[a]) {
        if (v == fa[a]) continue;
        dfs2(v);
    }
    bst[a] = inf;
    for (int i = 0; i < n; i++) {
        // fa len is i
        if (i < fl[a]) dp[a][i] = inf;
        else {
            dp[a][i] = tr[i] - tr[fl[a]];
            if (a == 1) dp[a][i] = 0;
        }
        // not involving c
        ui sbst = 0;
        ui str = 0;
        for (auto [v, d] : eg[a]) {
            if (v == fa[a]) continue;
            sbst += bst[v];
            if (dp[v][i] >= inf) {
                str = inf;
                break;
            }
            str += dp[v][i];
            if (str > inf) break;
        }
        sbst += 1ll * eg[a].size() * c;
        dp[a][i] += min(sbst, str);
        //cout << a << ' ' << i << ' ' << dp[a][i] << endl;
        chkmin(bst[a], dp[a][i]);
    }
}
int main() {
    cin >> n >> c;
    for (int i = 1; i < n; i++) {
        int u, v, s;
        scanf("%d%d%d", &u, &v, &s);
        tr.pb(s);
        eg[u].pb(mp(v, s));
        eg[v].pb(mp(u, s));
    }
    sort(tr.begin(), tr.end());
    dfs1(1);
    dfs2(1);
    cout << bst[1] << endl;
    return 0;
}
/*
5 100
1 2 10
1 3 5
1 4 7
2 5 9
*/

详细

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 6044kb

input:

13 20
1 8 101
1 9 30
1 2 100
1 3 100
2 4 75
2 5 70
2 6 82
2 7 77
3 10 73
3 11 69
3 12 83
3 13 79

output:

80

result:

wrong answer 1st lines differ - expected: '272', found: '80'