QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#487674#7684. Sweet SugarSATSKYWA 156ms3656kbC++141.3kb2024-07-23 06:39:312024-07-23 06:39:32

Judging History

你现在查看的是最新测评结果

  • [2024-07-23 06:39:32]
  • 评测
  • 测评结果:WA
  • 用时:156ms
  • 内存:3656kb
  • [2024-07-23 06:39:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;using ll=long long;using ld=long double;using pii=pair<int,int>;
const int M=998244353,P=20;const ll inf=1e17;const double eps=1e-10;
struct S
{	
	int n,K,res=0;vector<vector<int>>es;
	vector<int>val,lit;
	void ini()
	{
		cin>>n>>K;val.resize(n+1,0);lit=val;for(int i=1;i<=n;i++)cin>>val[i];
		es.resize(n+1);for(int i=1,u,v;i<n;i++)cin>>u>>v,es[u].push_back(v),es[v].push_back(u);
	}
	struct Ks
	{
		int sum=0,sp=M;//min_rt1_trs
	};
	Ks mg(Ks U,Ks D)
	{
		return Ks{U.sum+D.sum,min(U.sp,D.sp)};
	}
	Ks spr(int x,int lst)
	{
		lit[x]=1;Ks A={0,M};int d=0;
		for(auto&k:es[x])if(!lit[k])
		{
			auto p=spr(k,x);
			A=mg(A,p);d++;
		}
		if(d==1&&val[x]==1)
		{
			if(A.sum+1>=K){res++;return Ks{0,0};}
		}
		if(val[x]==1)A={A.sum+1,min(A.sp,A.sum+1)};
		else A={A.sum+val[x],A.sp};
		if(A.sum>=K)
		{
			if((A.sum-K)%2==0){res++;return Ks{0,0};}
			else if(A.sum-A.sp>=K){res++;return Ks{0,0};}
		}
		return A;
	}
	void solve()
	{
		for(int i=1;i<=n;i++)if(!lit[i])spr(i,0);cout<<res<<'\n';
	}
};
void precal()
{

}
int main()
{
	//freopen("1.in","r",stdin);
	//cout<<fixed<<setprecision(12);
	ios::sync_with_stdio(0);cin.tie(0);precal();
	int t=1;cin>>t;
	//clock_t a=clock();
	while(t--){S SS;SS.ini();SS.solve();}
	//cout<<"Time:"<<double(clock()-a)<<'\n';
}
/*

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3548kb

input:

4
7 5
1 2 1 2 2 1 2
1 2
2 3
3 4
3 5
5 6
5 7
2 2
1 0
1 2
1 1
1
1 2
1

output:

2
0
1
0

result:

ok 4 number(s): "2 0 1 0"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3656kb

input:

12
1 1
0
1 1
1
1 1
2
1 2
0
1 2
1
1 2
2
1 3
0
1 3
1
1 3
2
1 2000000
0
1 2000000
1
1 2000000
2

output:

0
1
0
0
0
1
0
0
0
0
0
0

result:

ok 12 numbers

Test #3:

score: -100
Wrong Answer
time: 156ms
memory: 3488kb

input:

200000
5 2
1 1 0 0 1
2 4
5 2
4 1
3 2
5 1
0 0 0 0 0
5 1
1 2
3 2
5 4
5 3
1 0 0 0 1
1 4
4 2
3 4
5 2
5 9
1 0 0 0 2
4 3
2 1
3 1
5 1
5 3
0 1 1 0 1
5 4
2 1
4 3
5 1
5 1
0 2 1 1 1
5 3
2 4
3 4
1 4
5 1
1 0 1 1 0
1 5
4 2
1 3
5 2
5 7
0 2 1 1 2
5 1
2 3
2 5
5 4
5 5
0 1 0 1 0
2 4
4 3
5 2
1 5
5 1
0 0 1 0 1
4 1
4 5
2...

output:

1
0
0
0
1
3
3
0
0
2
0
0
2
1
0
0
1
1
0
2
0
1
0
2
1
0
0
0
0
0
1
3
0
0
2
2
0
1
0
0
0
0
3
3
0
0
1
1
2
1
2
0
4
0
1
1
0
1
0
0
1
5
0
1
1
2
0
2
1
2
1
1
2
0
1
1
1
0
3
1
0
1
0
0
4
0
0
0
1
1
0
0
1
0
2
0
5
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
1
0
0
0
0
1
0
0
0
0
0
1
0
0
1
1
0
1
0
1
2
1
2
0
1
2
0
0
2
0
0
1
0
0
0
0
0
...

result:

wrong answer 32nd numbers differ - expected: '2', found: '3'