Submission #937037

# Submission time Handle Problem Language Result Execution time Memory
937037 2024-03-03T09:11:10 Z Beerus13 스파이 (JOI13_spy) C++14
100 / 100
114 ms 16472 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e3 + 5;

int n, m, root[2];
vector<int> g[2][N];
int dp[N][N];

void dfs1(int u) {
    for(int v : g[0][u]) {
        for(int i = 1; i <= n; ++i) {
            dp[v][i] += dp[u][i];
        }
        dfs1(v);
    }
}

void dfs2(int u) {
    for(int v : g[1][u]) {
        for(int i = 1; i <= n; ++i) {
            dp[i][v] += dp[i][u];
        }
        dfs2(v);
    }
}

void solve() {
    cin >> n >> m;
    for(int i = 1, p0, p1; i <= n; ++i) {
        cin >> p0 >> p1;
        if(p0 == 0) root[0] = i;
        else g[0][p0].push_back(i);
        if(p1 == 0) root[1] = i;
        else g[1][p1].push_back(i);
    }
    for(int i = 0, p0, p1; i < m; ++i) {
        cin >> p0 >> p1;
        dp[p0][p1]++;
    }
    dfs1(root[0]); dfs2(root[1]);
    for(int i = 1; i <= n; ++i) {
        cout << dp[i][i] << '\n';
    }
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int test = 1;
    // cin >> test;
    while(test--) solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 16216 KB Output is correct
2 Correct 38 ms 16220 KB Output is correct
3 Correct 23 ms 16216 KB Output is correct
4 Correct 26 ms 16220 KB Output is correct
5 Correct 35 ms 16216 KB Output is correct
6 Correct 32 ms 16220 KB Output is correct
7 Correct 30 ms 16216 KB Output is correct
8 Correct 31 ms 16216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 16368 KB Output is correct
2 Correct 81 ms 16320 KB Output is correct
3 Correct 76 ms 16252 KB Output is correct
4 Correct 81 ms 16472 KB Output is correct
5 Correct 114 ms 16300 KB Output is correct
6 Correct 83 ms 16120 KB Output is correct
7 Correct 109 ms 16360 KB Output is correct
8 Correct 97 ms 16216 KB Output is correct