提交记录 9965
提交时间 |
评测时间 |
2019-07-31 17:11:02 |
2020-08-01 01:59:47 |
#include<bits/stdc++.h>
using namespace std;
inline int getint(){
int ans=0;
char c=getchar();
while(c<'0'||c>'9'){
c=getchar();
}
while(c>='0'&&c<='9'){
ans=ans*10+c-'0';
c=getchar();
}
return ans;
}
const int N=100010,M=N<<1;
struct bian{
int l,e,n;
};
bian b[M];
int s[N],tot=0;
inline void add(int x,int y,int z){
tot++;
b[tot].l=z;
b[tot].e=y;
b[tot].n=s[x];
s[x]=tot;
}
long long maxson[N];
int cnt=0,mid=0;
void ss(int x,int fa){
//cout<<">>>"<<x<<endl;
for(int i=s[x];i;i=b[i].n){
if(b[i].e==fa)continue;
ss(b[i].e,x);
}
multiset<long long> sons;
for(int i=s[x];i;i=b[i].n){
if(b[i].e==fa)continue;
sons.insert(maxson[b[i].e]+b[i].l);
}
multiset<long long>::reverse_iterator it=sons.rbegin();
while(sons.size()){
if(*it>=mid){
cnt++;
sons.erase(sons.find(*it));
}else break;
}
while(sons.size()){
int t=*sons.begin();
sons.erase(sons.begin());
multiset<long long>::iterator itt=sons.lower_bound(mid-t);
if(itt==sons.end())maxson[x]=t;
else cnt++,sons.erase(itt);
}
//cout<<">> "<<x<<" "<<maxson[x]<<endl;
}
int main(){
int n=getint(),m=getint();
long long sum=0;
for(int i=0;i<n-1;i++){
int x=getint(),y=getint(),z=getint();
add(x,y,z);
add(y,x,z);
sum+=z;
}
long long l=0,r=sum/m+1;
while(l<r){
mid=(l+r+1)>>1;
cnt=0;
memset(maxson,0,sizeof(maxson));
ss(2,0);
if(cnt>=m)l=mid;
else r=mid-1;
//cout<<"---"<<mid<<"---"<<endl;
}
cout<<l;
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 329.91 us | 824 KB | Accepted | Score: 5 | 显示更多 |
Testcase #2 | 305.37 us | 824 KB | Accepted | Score: 5 | 显示更多 |
Testcase #3 | 311.19 us | 824 KB | Accepted | Score: 5 | 显示更多 |
Testcase #4 | 1.392 ms | 864 KB | Accepted | Score: 5 | 显示更多 |
Testcase #5 | 169.575 ms | 2 MB + 1004 KB | Accepted | Score: 5 | 显示更多 |
Testcase #6 | 99.244 ms | 2 MB + 620 KB | Accepted | Score: 5 | 显示更多 |
Testcase #7 | 92.979 ms | 2 MB + 1004 KB | Accepted | Score: 5 | 显示更多 |
Testcase #8 | 167.935 ms | 4 MB + 440 KB | Accepted | Score: 5 | 显示更多 |
Testcase #9 | 932.76 us | 976 KB | Accepted | Score: 5 | 显示更多 |
Testcase #10 | 22.999 ms | 5 MB + 272 KB | Accepted | Score: 5 | 显示更多 |
Testcase #11 | 41.782 ms | 8 MB + 248 KB | Accepted | Score: 5 | 显示更多 |
Testcase #12 | 337.41 us | 824 KB | Accepted | Score: 5 | 显示更多 |
Testcase #13 | 338.5 us | 824 KB | Accepted | Score: 5 | 显示更多 |
Testcase #14 | 447.72 us | 828 KB | Accepted | Score: 5 | 显示更多 |
Testcase #15 | 427.56 us | 836 KB | Accepted | Score: 5 | 显示更多 |
Testcase #16 | 973.86 us | 868 KB | Accepted | Score: 5 | 显示更多 |
Testcase #17 | 1.165 ms | 868 KB | Accepted | Score: 5 | 显示更多 |
Testcase #18 | 33.481 ms | 1 MB + 680 KB | Accepted | Score: 5 | 显示更多 |
Testcase #19 | 49.014 ms | 2 MB + 548 KB | Accepted | Score: 5 | 显示更多 |
Testcase #20 | 88.79 ms | 3 MB + 600 KB | Accepted | Score: 5 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:15:33 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠