/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 23ms 63.648 MiB
#2 Accepted 23ms 62.0 MiB
#3 Accepted 25ms 63.012 MiB
#4 Accepted 25ms 63.715 MiB
#5 Accepted 49ms 63.453 MiB
#6 Accepted 48ms 63.211 MiB
#7 Accepted 308ms 69.852 MiB
#8 Accepted 302ms 68.195 MiB
#9 Accepted 295ms 69.539 MiB
#10 Accepted 177ms 68.289 MiB

Code



#include <bits/stdc++.h>
using namespace std;

#define inf 0x3f3f3f3f
#define INF 2e18
#define PI acos(-1.0)
#define pii pair <int, int>
#define pLL pair <LL, LL>
#define SQR(a) ((a)*(a))
#define all(a) a.begin(), a.end()
#define Unique(a) sort(all(a)), a.erase(unique(all(a)), a.end())
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define Iterator(a) __typeof__(a.begin())
#define For(I, A, B) for(int I = (A); I < (B); I++)
#define Rep(I, N) For(I, 0, N)
#define ff first
#define ss second
#define LL long long
#define ULL unsigned long long
#define vi vector <int>
#define pb push_back
#define mk make_pair

#define Sieve

#ifdef Sieve
const int pSz = 10000007;
int prime_size;
vi prime;
bool np[pSz + 10];
void sieve() {
    prime.pb(2);
    for(LL i = 4; i < pSz; i += 2) np[i] = 1;
    for(LL i = 3; i < pSz; i += 2) {
        if(!np[i]) {
            prime.pb(i);
            for(LL j = i * i; j < pSz; j += (i << 1)) np[j] = 1;
        }
    }
    prime_size = prime.size();
}
#endif

const LL MOD = 1000000000 + 7;

LL BigMod(LL B, LL P, LL M = MOD) {
    LL R = 1;
    while(P) {
        if(P & 1) R = (R * B) % M;
        B = B / 2;
    }
    return R;
}

const int N = 2000006;

int st[N], ed[N], vs[N], Time, n, m, res[N], cur[N], bit[N];
vi G[N];

void DFS(int x, int F) {
    st[x] = ++Time;
    for(int y : G[x]) if(y != F) DFS(y, x);
    ed[x] = ++Time;
}

int main()
{
    int t, qq = 1; scanf("%d", &t);
    while(t--) {
        Time = 0;
        memset(bit, 0, sizeof bit);
        scanf("%d %d", &n, &m);
        For(i, 1, n + 1) G[i].clear();
        For(i, 1, n + 1) scanf("%d", &cur[i]);
        For(i, 1, n) {
            int x, y; scanf("%d %d", &x, &y);
            G[x].pb(y);
            G[y].pb(x);
        }
        DFS(1, 0);
        while(m--) {
            int x; scanf("%d", &x);
            bit[ st[x] ]++;
            bit[ ed[x] ]--;
        }
        For(i, 1, Time + 1) bit[i] += bit[i - 1];
        For(i, 1, n + 1) res[i] = (bit[ st[i] ] + cur[i]) & 1;
        printf("Case %d:", qq++);
        For(i, 1, n + 1) printf(" %d", res[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-24 14:04:07
Judged At
2023-11-29 16:57:26
Judged By
Score
100
Total Time
308ms
Peak Memory
69.852 MiB