답안 #34942

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
34942 2017-11-17T08:38:17 Z bql20000 스파이 (JOI13_spy) C++14
10 / 100
113 ms 13548 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 NAME            "spy"

using namespace std;
const int N = 1e5 + 8;

int n, Q, rootA, rootB, cnt[N], pb[N], ans[N];
vector <int> a[N], b[N], c[N];

void Enter() {
    cin >> n >> Q;
    ff(i, 1, n) {
        int p1, p2;
        cin >> p1 >> 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;
        cin >> r >> b;
        c[r].push_back(b);
    }
}

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

void DFSA(int u) {
    for (int x : c[u]) cnt[x]++;
    for (int i = u; i; i = pb[i]) ans[u] += cnt[i];

    for (int v : a[u]) DFSA(v);

    for (int x : c[u]) cnt[x]--;
}

void Process() {
    DFSB(rootB);
    DFSA(rootA);
    ff(i, 1, n) cout << ans[i] << endl;
}

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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 10380 KB Output is correct
2 Correct 3 ms 10380 KB Output is correct
3 Correct 3 ms 10380 KB Output is correct
4 Correct 3 ms 10380 KB Output is correct
5 Correct 3 ms 10380 KB Output is correct
6 Correct 3 ms 10380 KB Output is correct
7 Correct 0 ms 10380 KB Output is correct
8 Correct 0 ms 10380 KB Output is correct
9 Correct 3 ms 10380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 10512 KB Output is correct
2 Runtime error 6 ms 10512 KB Execution killed because of forbidden syscall writev (20)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 113 ms 13548 KB Execution killed because of forbidden syscall writev (20)
2 Halted 0 ms 0 KB -