QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#487680 | #7684. Sweet Sugar | SATSKY | WA | 151ms | 3656kb | C++14 | 1.6kb | 2024-07-23 06:42:49 | 2024-07-23 06:42:50 |
Judging History
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;
int xt,tc;
bool o;
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];
if(o)
{
cout<<n<<' '<<K<<'\n';
for(int i=1;i<=n;i++)cout<<val[i]<<" \n"[i==n];
}
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);
if(o)
{
cout<<u<<' '<<v<<'\n';
}
}
}
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);
if(xt<=1000)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;xt=t;
//clock_t a=clock();
while(t--){tc++;o=(tc==32);S SS;SS.ini();SS.solve();}
//cout<<"Time:"<<double(clock()-a)<<'\n';
}
/*
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3656kb
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: 3460kb
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: 151ms
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:
5 1 0 2 2 1 1 1 3 4 2 4 3 5 3
result:
wrong answer 1st numbers differ - expected: '1', found: '5'