QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#381743 | #2161. The Cost of Speed Limits | SolitaryDream# | WA | 1ms | 5884kb | C++17 | 1.2kb | 2024-04-07 20:44:41 | 2024-04-07 20:44:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int N = 20010;
int n, C, fc[N], fmn[N];
int f[N][N];
vector<pii> g[N];
vector<int> L;
inline void Dp(int x, int fa) {
int sm = 0, bnd = 0;
for (auto [y, z]: g[x]) if (y != fa) {
fc[y] = lower_bound(L.begin(), L.end(), z) - L.begin() + 1;
Dp(y, x);
sm += fmn[y];
bnd = max(bnd, fc[y]);
for (int j = bnd; j <= L.size(); ++j) f[x][j] += f[y][j];
}
sm += C * (x == 1 ? g[x].size() : g[x].size() - 1);
fmn[x] = 2e9;
for (int j = fc[x]; j <= L.size(); ++j) {
int delta = L[j - 1];
if (x != 1) delta -= L[fc[x] - 1];
if (x == 1) delta = 0;
if (j < bnd) f[x][j] = 2e9;
f[x][j] = min(sm, f[x][j]) + delta;
fmn[x] = min(fmn[x], f[x][j]);
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> C;
for (int i = 1, x, y, z; i < n; ++i) {
cin >> x >> y >> z;
L.push_back(z);
g[x].push_back(pii(y, z));
g[y].push_back(pii(x, z));
}
sort(L.begin(), L.end());
L.erase(unique(L.begin(), L.end()), L.end());
Dp(1, 0);
cout << fmn[1] << endl;
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5884kb
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:
233
result:
wrong answer 1st lines differ - expected: '272', found: '233'