/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 3.777 MiB
#2 Accepted 3ms 5.266 MiB
#3 Accepted 4ms 3.738 MiB
#4 Accepted 4ms 4.777 MiB
#5 Accepted 52ms 5.402 MiB
#6 Accepted 50ms 4.434 MiB
#7 Accepted 610ms 10.098 MiB
#8 Accepted 634ms 9.891 MiB
#9 Accepted 592ms 10.117 MiB
#10 Accepted 321ms 8.367 MiB

Code

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

const int sz = 1e5 + 10;
const int MAXNODE = 1e5;
const int MAXQUERY = 1e5;
int ar[sz], vis[sz], st[sz], en[sz], br[sz * 3], tim, vis_cnt;
vector < int > G[sz];

void dfs( int u ) {
    vis_cnt++;
    vis[u] = 1;
    st[u] = ++tim;
//    br[tim] = ar[u];
    for( int v: G[u] ) {
        if( !vis[v] ) {
            dfs( v );
        }
    }
    en[u] = ++tim;
}

int main() {
    #ifdef CLown1331
//        freopen( "input03.txt","r",stdin );
//        freopen( "output03.txt","w+",stdout );
    #endif /// CLown1331
    int t, n, m;
    cin >> t;
    assert( 1 <=t && t <= 5 );
    for( int cs=1; cs<=t; cs++ ) {
        cin >> n >> m;
        assert( n <= MAXNODE && m <= MAXQUERY );
        int a_size = 0;
        for( int i=1; i<=n; i++ ) {
            cin >> ar[i];
            assert( 0 <= ar[i] && ar[i] <= 1 );
            a_size++;
        }
        assert( a_size == n );
        for( int i=0; i<=n; i++ ) {
            G[i].clear();
            vis[i] = 0;
        }
        memset( br, 0, sizeof br );
        for( int i=1; i<n; i++) {
            int x, y;
            cin >> x >> y;
            assert( x != y );
            assert( 1 <= x && x <= n );
            assert( 1 <= y && y <= n );
            G[x].push_back( y );
            G[y].push_back( x );
        }
        vis_cnt = 0;
        tim = 0;
        dfs( 1 );
        assert( vis_cnt == n );
//        for( int i=1; i<=n; i++ ) {
//            cerr << br[ st[i] ] << " " << st[i] << " " << en[i] << "\n";
//        }
        for( int i=0; i<m; i++ ) {
            int x;
            cin >> x;
            assert( 1 <= x && x <= n );
            br[ st[x] ]++;
            br[ en[x] ]--;
        }
        for( int i=1; i<=tim; i++ ) {
            br[i] += br[i - 1];
        }
        printf( "Case %d:", cs );
        for( int i=1; i<=n; i++ ) {
            cout << " " << ( br[ st[i] ] + ar[i] ) % 2;
        }
        cout << "\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 13:46:59
Judged At
2024-02-14 21:26:21
Judged By
Score
100
Total Time
634ms
Peak Memory
10.117 MiB