/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 3ms 2.984 MiB
#2 Wrong Answer 3ms 2.82 MiB

Code

//on the name of Allah:)
#include<bits/stdc++.h>
#define int         long long
#define endl        "\n"
#define pi          2 * acos(0.0)
#define mod         1000000007
#define Mul(a,b)    (a%mod * b%mod)%mod
#define Add(a,b)    (a%mod + b%mod)%mod
#define all(x)      (x).begin(),(x).end()
#define allr(x)     (x).rbegin(),(x).rend()
#define gcd(x, y)   (__gcd(x, y))
#define lcm(x, y)   ((x/gcd(x, y))*y)
#define faster      cin.tie(NULL), cout.tie(NULL);
#define TC          int t ; cin>>t ; while (t--)
const int N = 1e5 + 7;
using namespace std;

int node,edge;
vector<int> g[N];
bool vis[N];
queue<int>q;
int par[N];

void bfs(int x) {
    par[x] = x;
    vis[x]=true;
    q.push(x);
    while(!q.empty()) {
        int u = q.front();
        q.pop();
        for(auto v: g[u]) {
            if(!vis[v]) {
                q.push(v);
                vis[v] = true;
                par[v] = u;
            }
        }
    }

}
int cs = 1;
void s()
{
    int q;
    cin >> node >> q;
    vector<int>a(node+1);
    for(int i=1;i<=node;i++) {
        cin >> a[i];
    }
    edge = node-1;
    while(edge--) {
        int u,v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    bfs(1);

    while(q--) {
        int tog;
        cin >> tog;
        if(a[tog]==1)a[tog] = 0;
        else a[tog] = 1;
    }



    for(int i=1;i<=node;i++) {
        if(a[i]==0) {
            int n = a[i];
            while(par[n]!=n) {
                if(a[par[n]]==1) {
                    a[i] = 1;
                    break;
                }
                n = par[n];
            }
        }
    }
    cout << "Case " << cs++ << ": ";
    for(int i=1;i<=node;i++) {
        cout << a[i] << " ";
    }cout << endl;
    for(int i=1;i<=node;i++) {
        par[i] = 0;
        vis[i] = false;
    }

}
int32_t main()
{   ios::sync_with_stdio(false);
    TC
    s();
    cs = 1;

}



Information

Submit By
Type
Submission
Problem
P1003 Tahsin and Tree
Contest
Beta Round #1
Language
C++17 (G++ 13.2.0)
Submit At
2023-11-29 17:58:44
Judged At
2024-11-11 03:50:15
Judged By
Score
0
Total Time
3ms
Peak Memory
2.984 MiB