Accepted
Code
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c,l,m,n;
scanf("%d",&a);
for(int j=1; j<=a; j++)
{
scanf("%d%d",&b,&c);
vector<int> v[b+1];int x[b+1];
for(int i=1; i<=b; i++)
{
scanf("%d",&x[i]);
}
for(int i=1; i<b; i++)
{
scanf("%d%d",&m,&n);
v[min(m,n)].push_back(max(m,n));
}
for(int i=0; i<c; i++)
{
scanf("%d",&l);
queue<int> q;
q.push(l);
if(x[l]==1)
x[l]=0;
else
x[l]=1;
while(!q.empty())
{
int u = q.front();
q.pop();
for(int h=0; h<v[u].size(); h++)
{
q.push(v[u][h]);
if(x[v[u][h]]==1)
x[v[u][h]]=0;
else
x[v[u][h]]=1;
}
}
}
printf("Case %d:",j);
for(int i=1; i<=b; i++)
{
printf(" %d",x[i]);
}
printf("\n");
}
return 0;
}
Information
- Submit By
- Type
- Submission
- Problem
- P1003 Tahsin and Tree
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2023-11-29 20:52:49
- Judged At
- 2024-11-11 03:50:08
- Judged By
- Score
- 100
- Total Time
- 468ms
- Peak Memory
- 5.77 MiB