Meatherm @ 2020-01-30 21:46:21
标题是假的。
无药可救的点分治...先不说这算法本身复杂度就不对,帮我康康为啥 WA 罢 /大哭
# include <bits/stdc++.h>
# define rr register
const int N=10010;
struct Edge{
int to,next,v;
}edge[N<<1];
int head[N],sum;
int dis[N];
int temp[N],cnt;
int size[N];
int subt[N];
int n,m;
bool use[N];
int tot;
int root;
int ans[10000001];
inline int read(void){
int res,f=1;
char c;
while((c=getchar())<'0'||c>'9')
if(c=='-')f=-1;
res=c-48;
while((c=getchar())>='0'&&c<='9')
res=res*10+c-48;
return res*f;
}
inline void add(int x,int y,int v){
edge[++sum].to=y;
edge[sum].next=head[x];
edge[sum].v=v;
head[x]=sum;
return;
}
void getroot(int i,int fa){
size[i]=1;
subt[i]=0;
for(rr int j=head[i];j;j=edge[j].next){
if(edge[j].to==fa||use[edge[j].to])
continue;
getroot(edge[j].to,i);
size[i]+=size[edge[j].to];
subt[i]=std::max(subt[i],size[edge[j].to]);
}
subt[i]=std::max(subt[i],tot-size[i]);
if(subt[root]>subt[i]){
root=i;
}
// if(!fa){
// printf("root is %d\n",root);
// }
return;
}
void getdis(int i,int fa){
temp[++cnt]=dis[i];
for(rr int j=head[i];j;j=edge[j].next){
if(edge[j].to==fa||use[edge[j].to])
continue;
dis[edge[j].to]=dis[i]+edge[j].v;
getdis(edge[j].to,i);
}
return;
}
inline void calc(int i,int len,int val){
dis[i]=len;
cnt=0;
getdis(i,0);
for(rr int i=1;i<=cnt;++i){
for(rr int j=1;j<=cnt;++j){
if(dis[i]+dis[j]>1e7)
continue;
ans[dis[i]+dis[j]]+=val;
}
}
return;
}
void work(int i){
use[i]=true;
calc(i,0,1);
for(rr int j=head[i];j;j=edge[j].next){
if(use[edge[j].to])
continue;
calc(edge[j].to,edge[j].v,-1);
root=0,tot=size[edge[j].to];
getroot(edge[j].to,0);
work(root);
}
return;
}
int main(void){
subt[0]=1e9;
n=read(),m=read();
for(rr int i=1,x,y,v;i<n;++i){
x=read(),y=read(),v=read();
add(x,y,v);
add(y,x,v);
}
tot=n;
getroot(1,0);
work(root);
for(rr int i=1,x;i<=m;++i){
x=read();
if(ans[x]){
puts("AYE");
}else{
puts("NAY");
}
}
return 0;
}
by gongcharlie @ 2020-01-30 21:47:04
所以应该叫大佬汉子求助【狗头】
by zimujun @ 2020-01-30 21:47:06
鉴定完毕,不是妹子
by SisconHL @ 2020-01-30 21:48:04
orz 神Meatherm
by Meatherm @ 2020-01-30 21:49:57
@hepta_lhd /kel 您帮我康康罢
by zimujun @ 2020-01-30 21:50:59
@Meatherm 又小又强 我再也比不过ta了
by SisconHL @ 2020-01-30 21:52:29
窝不会(大哭
by Register @ 2020-01-30 21:53:27
@Meatherm 您这个是假的算法吧,要去掉子树内的情况
by 茅场晶彦 @ 2020-01-30 21:55:21
神Meatherm
by Meatherm @ 2020-01-30 21:57:00
@songhaoran % 神仙 shr
我在 work()
里面写了的吧,还是说我写假了?
void work(int i){
use[i]=true;
calc(i,0,1);
for(rr int j=head[i];j;j=edge[j].next){
if(use[edge[j].to])
continue;
calc(edge[j].to,edge[j].v,-1);// 这里
root=0,tot=size[edge[j].to];
getroot(edge[j].to,0);
work(root);
}
return;
}
by SSerxhs @ 2020-01-30 21:57:29
不是袜子,走了走了