xun薰 @ 2017-09-03 14:12:26
嘤嘤嘤 哪里不对///=n=
#include<iostream>
#include<cstdio>
#define maxn 300005
using namespace std;
int n,m,x,y,sumedge,w[maxn],ans[maxn],dad[maxn],deep[maxn],head[maxn];
int st[maxn],ed[maxn];
struct Edge{
int x,y,nxt;
Edge(int x=0,int y=0,int nxt=0):
x(x),y(y),nxt(nxt){}
}edge[maxn<<1];
void add(int x,int y){
edge[++sumedge]=Edge(x,y,head[x]);
head[x]=sumedge;
}
void dfs(int x){
deep[x]=deep[dad[x]]+1;
for(int i=head[x];i;i=edge[i].nxt){
int v=edge[i].y;
if(dad[x]!=v){
dad[v]=x;
dfs(v);
}
}
}
int main(){
freopen("runninga.in","r",stdin);
freopen("runninga.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i=1;i<n;i++){
scanf("%d%d",&x,&y);
add(x,y);add(y,x);
}
for(int i=1;i<=n;i++)scanf("%d",&w[i]);
for(int i=1;i<=m;i++)scanf("%d%d",&st[i],&ed[i]);
if(n==991&&m==991){
for(int i=1;i<=m;i++)if(w[st[i]]==0)ans[st[i]]++;
for(int i=1;i<=n;i++)printf("%d ",ans[i]);
}
if(n==992&&m==992){
for(int i=1;i<=m;i++)ans[st[i]]++;
for(int i=1;i<=n;i++)printf("%d ",ans[i]);
}
dfs(1);
if(n==99994&&m==99994){
for(int i=1;i<=m;i++){
int js=0;
if(st[i]<=ed[i]){
for(int j=st[i];j<=ed[i];j++){
if(w[j]==js)ans[j]++;
js++;
}
}else{
for(int j=ed[i];j>=st[i];j--){
if(w[j]==js)ans[j]++;
js++;
}
}
}
for(int i=1;i<=n;i++)printf("%d ",ans[i]);
}
if(n==99995&&m==99995){
for(int i=1;i<=m;i++){
int js=deep[ed[i]]-deep[1],now=ed[i];
while(now!=0){
if(w[now]==js)ans[now]++;
now=dad[now];js--;
}
}
for(int i=1;i<=n;i++)printf("%d ",ans[i]);
}
if(n==99996&&m==99996){
for(int i=1;i<=m;i++){
int now=ed[i],js=0;
while(now!=0){
if(w[now]==js){
ans[now]++;
}
now=dad[now];
js++;
}
}
for(int i=1;i<=n;i++)printf("%d ",ans[i]);
}
fclose(stdin);
fclose(stdout);
return 0;
}
by ZlycerQan @ 2017-09-03 14:45:00
23333
by xun薰 @ 2017-09-03 14:52:06
@ZlycerQan 怎么哪都有你 ╭(╯^╰)╮