QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#391576 | #2161. The Cost of Speed Limits | RobeZH | WA | 1ms | 3796kb | C++23 | 1.9kb | 2024-04-16 17:15:23 | 2024-04-16 17:15:23 |
Judging History
answer
#pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>
// #include<atcoder/all>
#define FR(i,n) for(int i=0;i<n;++i)
// #define rep(i,n) for(int i=1;i<=n;++i)
#define eb emplace_back
#define st first
#define nd second
#define x1 fxxkcjb
#define y1 fxxkyzc
#define x2 fxxkzzy
#define y2 fxxknitit
using namespace std;
namespace R=ranges;
template<typename T>
using func=function<T>;
template<typename T>
using vec=vector<T>;
using ll=long long;
using ld=long double;
using i128=__int128;
using pii=pair<int,int>;
const int inf=(int)2e9+9;
void sol(){
int n,c;cin>>n>>c;
vector g(n,vector<pii>());
vector<int>len(n-1);
FR(tim,n-1){
int u,v,w;cin>>u>>v>>w;--u,--v;
g[u].eb(v,w);g[v].eb(u,w);
len[tim]=w;
}
vector dp(n,vector<int>(n-1));
vector<ll>dp2(n-1);
func<void(int,int,int)>dfs=[&](int x,int fa,int lalen){
// cerr<<x<<endl;
if(x!=0){
FR(i,n-1)dp[x][i]=(len[i]<lalen?inf:len[i]-lalen);
}else{
FR(i,n-1)dp[x][i]=0;
}
for(auto[y,dis]:g[x])if(y!=fa){
dfs(y,x,dis);
FR(i,n-1)dp[x][i]=min((ll)inf,(ll)dp[x][i]+dp[y][i]);
}
if(x!=0){
FR(i,n-1)dp2[i]=dp[x][i]+c;
}else{
FR(i,n-1)dp2[i]=0;
}
for(auto[y,dis]:g[x])if(y!=fa){
ll mi=R::min(dp[y]);
FR(i,n-1)dp2[i]=min((ll)inf,(ll)dp2[i]+c+mi);
}
FR(i,n-1){
dp[x][i]=min((ll)dp[x][i],dp2[i]);
// cerr<<x<<" "<<i<<" "<<dp[x][i]<<endl;
}
};
dfs(0,-1,-1);
int ans=dp[0][0];
FR(i,n-1)ans=min(ans,dp[0][i]);
cout<<ans<<"\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
sol();
return 0;
}
/*
5 2
1 2 10
1 3 5
1 4 7
2 5 9
*/
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3796kb
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:
272
result:
ok single line: '272'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3568kb
input:
9 10 1 6 26 2 6 27 3 6 28 4 6 29 5 6 30 7 9 14 8 9 1 9 6 10
output:
75
result:
wrong answer 1st lines differ - expected: '60', found: '75'