/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 1ms 540.0 KiB
#3 Accepted 1ms 540.0 KiB
#4 Accepted 1ms 356.0 KiB
#5 Accepted 32ms 992.0 KiB
#6 Accepted 33ms 876.0 KiB
#7 Accepted 396ms 5.781 MiB
#8 Accepted 391ms 5.672 MiB
#9 Accepted 381ms 5.613 MiB
#10 Accepted 210ms 4.398 MiB

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
2023-11-29 21:56:56
Judged By
Score
100
Total Time
396ms
Peak Memory
5.781 MiB