Submission #35255

# Submission time Handle Problem Language Result Execution time Memory
35255 2017-11-19T10:19:15 Z bql20000 스파이 (JOI13_spy) C++14
100 / 100
439 ms 247312 KB
#include <bits/stdc++.h>

#define ff(i,a,b)       for(int i=(a), _b=(b); i <= _b; ++i)
#define gg(i,a,b)       for(int i=(a), _b=(b); i >= _b; --i)
#define REP(i ,b)       for(int i=(0), _b=(b); i <  _b; ++i)
#define long            long long
#define ALL(v)          v.begin(), v.end()
#define endl            '\n'
#define Love(a)         {cerr << #a << " = " << a << endl;}
#define _               << " , " <<
#define X               first
#define Y               second
#define gc getchar
#define pc putchar

#define NAME            "spy"

using namespace std;
const int N = 2007, M = 5e5+7;
typedef bitset<M> BS;

BS setA[N], setB[N], cur;

int n, Q, rootA, rootB;
vector <int> a[N], b[N];

inline void read(int &x){
    register int c = gc();
    x = 0;
    int neg = 0;
    for (;((c<48 || c>57) && c != '-') ;c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}
inline void writeln(int x){

         char buffor[21];
         register int i=0;
         int neg=0; if (x<0) {neg=1; x= -x;}
         do{
               buffor[i++]=(x%10)+'0';
               x/=10;
            } while(x);
           i--;
           if (neg) pc('-');
           while(i>=0) pc(buffor[i--]);
           pc('\n');
       }

void Enter() {
    read(n);
    read(Q);
    ff(i, 1, n) {
        int p1, p2;
        read(p1);
        read(p2);
        if (p1 == 0) rootA = i;
        if (p2 == 0) rootB = i;
        a[p1].push_back(i);
        b[p2].push_back(i);
    }
    ff(i, 1, Q) {
        int r, b;
        read(r);    setA[r].set(i);
        read(b);    setB[b].set(i);
    }
}

void DFSA(int u) {
    for (int v : a[u]) {
       setA[v] |= setA[u];
        DFSA(v);
    }
}

void DFSB(int u) {
    for (int v : b[u]) {
       setB[v] |= setB[u];
        DFSB(v);
    }
}

void Process() {
    DFSB(rootB);
    DFSA(rootA);
    ff(i, 1, n) {
        BS ans = setA[i] & setB[i];
        writeln(ans.count());
    }
}

int main() {
    //ios_base::sync_with_stdio(0);  cin.tie(0);
    //freopen(NAME".inp", "r", stdin);
    //freopen(NAME".out", "w", stdout);
    Enter();
    Process();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 247180 KB Output is correct
2 Correct 16 ms 247180 KB Output is correct
3 Correct 19 ms 247180 KB Output is correct
4 Correct 13 ms 247180 KB Output is correct
5 Correct 16 ms 247180 KB Output is correct
6 Correct 9 ms 247180 KB Output is correct
7 Correct 26 ms 247180 KB Output is correct
8 Correct 16 ms 247180 KB Output is correct
9 Correct 0 ms 247180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 166 ms 247312 KB Output is correct
2 Correct 159 ms 247312 KB Output is correct
3 Correct 153 ms 247180 KB Output is correct
4 Correct 163 ms 247180 KB Output is correct
5 Correct 173 ms 247312 KB Output is correct
6 Correct 196 ms 247312 KB Output is correct
7 Correct 179 ms 247312 KB Output is correct
8 Correct 163 ms 247312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 439 ms 247312 KB Output is correct
2 Correct 219 ms 247312 KB Output is correct
3 Correct 303 ms 247180 KB Output is correct
4 Correct 276 ms 247180 KB Output is correct
5 Correct 393 ms 247312 KB Output is correct
6 Correct 216 ms 247312 KB Output is correct
7 Correct 403 ms 247312 KB Output is correct
8 Correct 419 ms 247312 KB Output is correct