AThousandSuns @ 2018-08-10 07:02:07
第二个点狂WA不止,和题解对拍不出任何不同点了……
#include<bits/stdc++.h>
using namespace std;
struct edge{
int v,w,nxt;
}e[20020];
int n,m,ecnt,head[10010];
inline void add(int u,int v,int w){
e[++ecnt]=(edge){v,w,head[u]};head[u]=ecnt;
}
int root,tot,son[10010],size[10010];
bool vis[10010];
void getroot(int u,int f){
son[u]=0;
size[u]=1;
for(int i=head[u];i;i=e[i].nxt){
int v=e[i].v;
if(v==f || vis[v]) continue;
getroot(v,u);
size[u]+=size[v];
son[u]=max(son[u],size[v]);
}
son[u]=max(son[u],tot-size[u]);
if(son[u]<son[root]) root=u;
}
int dis[10010],dcnt;
void getdis(int u,int f,int d){
dis[++dcnt]=d;
for(int i=head[u];i;i=e[i].nxt){
int v=e[i].v;
if(v==f || vis[v]) continue;
getdis(v,u,d+e[i].w);
}
}
int tmp[10010],tcnt,query[101];
bool exist[10001000],ans[101];
void getans(int u){
tcnt=0;
for(int i=head[u];i;i=e[i].nxt){
int v=e[i].v;
if(vis[v]) continue;
dcnt=0;
getdis(v,u,e[i].w);
for(int j=1;j<=m;j++)
for(int k=1;k<=dcnt;k++)
if(query[j]>=dis[k]) ans[j]|=exist[query[j]-dis[k]];
for(int j=1;j<=dcnt;j++)
if(dis[j]<=10000000) exist[tmp[++tcnt]=dis[j]]=true;
}
for(int i=1;i<=tcnt;i++) exist[tmp[i]]=false;
}
void getall(int u){
vis[u]=true;
getans(u);
for(int i=head[u];i;i=e[i].nxt){
int v=e[i].v;
if(vis[v]) continue;
tot=size[v];
root=0;
getroot(v,0);
getall(root);
}
}
int main(){
son[0]=10001;
exist[0]=true;
scanf("%d%d",&n,&m);
for(int i=1;i<n;i++){
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
add(u,v,w);add(v,u,w);
}
for(int i=1;i<=m;i++) scanf("%d",query+i);
tot=n;
getroot(1,0);
getall(root);
for(int i=1;i<=m;i++) puts(ans[i]?"AYE":"NAY");
}
by p_b_p_b @ 2018-08-10 15:17:52
@AThousandSuns
怎么看也没问题,一定是您tql,评测机不想让您过
您也可以 @AThousandMoons
by p_b_p_b @ 2018-08-10 15:18:09
@AThousandMoon
by mytester @ 2018-08-10 15:24:18
@AThousandSuns 送您那组数据:
12 3
1 2 16
1 3 17
3 4 19
4 5 8
5 6 7
1 7 19
1 8 2
7 9 18
5 10 0
7 11 11
5 12 7
16
13
29
by mytester @ 2018-08-10 15:35:59
@AThousandSuns 看出问题了。边权有0,你把exist[0]赋为false啦
by mytester @ 2018-08-10 15:37:54
可以AC的getans():
void getans(int u){
tcnt=0;
for(int i=head[u];i;i=e[i].nxt){
int v=e[i].v;
if(vis[v]) continue;
dcnt=0;
getdis(v,u,e[i].w);
for(int j=1;j<=m;j++)
for(int k=1;k<=dcnt;k++)
if(query[j]>=dis[k]) ans[j]|=exist[query[j]-dis[k]];
for(int j=1;j<=dcnt;j++)
if(dis[j]<=10000000) exist[tmp[++tcnt]=dis[j]]=true;
}
for(int i=1;i<=tcnt;i++) exist[tmp[i]]=false;
exist[0]=1;//加上这一句就搞定了
}
by mytester @ 2018-08-10 15:38:35
@AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns @AThousandSuns
by watermoon @ 2018-08-10 21:01:49
找我这个蒟蒻干什么,我不会淀粉质(手动滑稽
by AThousandSuns @ 2018-08-11 00:06:58
@p_b_p_b 谢大佬(妈呀手滑评了tg+/sx-咋办)
by p_b_p_b @ 2018-08-11 12:41:16
@AThousandSuns 太强啦,竟然只是sx-!!!