// Problem: No.2618 除霊 // Contest: yukicoder // URL: https://yukicoder.me/problems/no/2618 // Memory Limit: 512 MB // Time Limit: 2000 ms #include #define debug(x) cerr<<(#x)<<" "<<(x)< #define rep(i,a,b) for(ll i=(a);i<=(b);++i) #define per(i,a,b) for(ll i=(a);i>=(b);--i) using namespace std; bool Mbe; ll read(){ ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } void write(ll x){ if(x<0)putchar('-'),x=-x; if(x>9)write(x/10); putchar(x%10+'0'); } const ll N=5e5+9; ll n,m,a[N],po[N],sum[N],tr[N],tag[N],ent[N],fa[N]; vectorto[N]; void dfs(ll x,ll f){ fa[x]=f; for(ll y:to[x]){ if(y==f)continue; dfs(y,x); sum[x]+=tr[y]; tr[x]+=tr[y]; if(!ent[y]&&!tag[y]&&tag[x])tr[x]++; ent[x]+=tag[y]; } tr[x]+=(ent[x]||tag[x]); } bool Med; int main(){ cerr<