/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 4ms 532.0 KiB
#2 Accepted 3ms 532.0 KiB
#3 Accepted 2ms 532.0 KiB
#4 Accepted 2ms 552.0 KiB
#5 Accepted 33ms 1.012 MiB
#6 Accepted 34ms 976.0 KiB
#7 Accepted 407ms 5.77 MiB
#8 Accepted 443ms 5.664 MiB
#9 Accepted 468ms 5.586 MiB
#10 Accepted 220ms 4.52 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
2024-11-11 03:50:08
Judged By
Score
100
Total Time
468ms
Peak Memory
5.77 MiB