/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 4ms 2.82 MiB
#2 Wrong Answer 3ms 2.777 MiB
#3 Wrong Answer 3ms 3.07 MiB
#4 Wrong Answer 2ms 2.777 MiB
#5 Wrong Answer 28ms 4.875 MiB
#6 Wrong Answer 28ms 5.008 MiB
#7 Wrong Answer 386ms 18.812 MiB
#8 Wrong Answer 422ms 18.801 MiB
#9 Wrong Answer 462ms 18.98 MiB
#10 Wrong Answer 181ms 12.832 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
Language
C++17 (G++ 13.2.0)
Submit At
2023-11-29 21:19:55
Judged At
2023-12-01 15:31:08
Judged By
Score
100
Total Time
462ms
Peak Memory
18.98 MiB