QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#725231#7684. Sweet Sugarbugmaker3243WA 35ms7804kbC++232.4kb2024-11-08 16:46:002024-11-08 16:46:01

Judging History

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

  • [2024-11-08 16:46:01]
  • 评测
  • 测评结果:WA
  • 用时:35ms
  • 内存:7804kb
  • [2024-11-08 16:46:00]
  • 提交

answer

#include<bits/stdc++.h>
#define N 500005
//#define gc() (iS==iT?(iT=(iS=ibuf)+fread(ibuf,1,SIZE,stdin),(iS==iT?EOF:*iS++)):*iS++)
#define gc() getchar()
#define fi first
#define se second
#define Kamisato return
#define Ayaka 0;
#define file(_s) freopen(#_s".in","r",stdin);freopen(#_s".out","w",stdout);
//#define CHECK_MEMORY ___JQH___
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9;
const ll INF=2e18;
bool Memory_Begin;
namespace IO{const int SIZE=(1<<21)+1;char ibuf[SIZE],*iS,*iT,obuf[SIZE],*oS=obuf,*oT=oS+SIZE-1,c,qu[55];int f,qr;inline void flush(){fwrite(obuf,1,oS-obuf,stdout),oS=obuf,fflush(stdout);}inline void putc(char x){*oS++=x;if(oS==oT)flush();}template <class I>inline void read(I &x){for(f=1,c=gc();c<'0'||c>'9';c=gc())if(c=='-')f=-1;for(x=0;c<='9'&&c>='0';c=gc())x=x*10+(c&15);x*=f;}template <class I>inline void print(I x){if(!x)putc('0');if(x<0)putc('-'),x=-x;while(x)qu[++qr]=x%10+'0',x/=10;while(qr)putc(qu[qr --]);}inline void reads(string &s){s.clear();for(c=gc();c<33||c>126;)c=gc();for(;c>=33&&c<=126;c=gc())s.push_back(c);}inline void prints(string s){for(char c:s)putc(c);}struct Flusher_ {~Flusher_(){flush();}}io_flusher_;}
using IO::read;using IO::putc;using IO::print;using IO::reads;using IO::prints;
template<class I>I updiv(I x,I y){return (x%y==0?x/y:x/y+1);}
template<class I>bool cmin(I &x,I y){if(x>y)return x=y,1;return 0;}
template<class I>bool cmax(I &x,I y){if(x<y)return x=y,1;return 0;}

int n,m,ans,c[N];
vector<int>s[N];
int f[N][2];
bool cut[N];
void dfs(int x,int prt)
{
	f[x][c[x]&1]=c[x];
	for(int y:s[x])
	{
		if(y==prt) continue;
		dfs(y,x);
		if(cut[y]) continue;
		int tmp[2]={f[x][0],f[x][1]};
		for(int i=0;i<2;i++)
			for(int j=0;j<2;j++)
				cmax(f[x][(i+j)&1],tmp[i]+f[y][j]);
	}
	if(f[x][m&1]>=m) ans++,cut[x]=1;
}
void solve()
{
	read(n),read(m),ans=0;
	for(int i=1;i<=n;i++) read(c[i]),f[i][0]=f[i][1]=0;
	for(int i=1,x,y;i<n;i++)
	{
		read(x),read(y);
		s[x].push_back(y);
		s[y].push_back(x);
	}
	dfs(1,0);
	print(ans),putc('\n');
}
void clear()
{
	for(int i=1;i<=n;i++) s[i].clear(),cut[i]=0;
}
bool Memory_End;
signed main()
{
#ifdef CHECK_MEMORY
	cerr<<"Memory: "<<(&Memory_End-&Memory_Begin)/1048576.0<<" MiB\n";
#endif
	int T; read(T);
	while(T--) solve(),clear();
	Kamisato Ayaka
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 7804kb

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: 1ms
memory: 7664kb

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: 35ms
memory: 7744kb

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
3
1
0
0
0
2
0
1
3
0
1
2
2
1
1
0
0
0
0
3
3
0
0
1
1
2
1
2
1
4
0
1
1
0
1
0
0
1
5
0
1
1
2
0
2
1
2
1
1
2
1
1
1
1
0
3
1
1
1
2
2
4
1
0
1
1
1
1
0
1
1
2
2
5
1
1
1
0
0
0
0
0
0
1
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 24th numbers differ - expected: '2', found: '3'