Submission #448228

# Submission time Handle Problem Language Result Execution time Memory
448228 2021-07-29T10:45:33 Z hizuna 스파이 (JOI13_spy) C++17
100 / 100
228 ms 16452 KB
#include <bits/stdc++.h>

using namespace std;
using lint = long long;

vector<int> child[2][2003];
int f[2003][2003], N, M, a, r, s, root[2];

void dfsi(int u) {
    for(auto v : child[0][u]) {
        for(int i = 0; i < N; i++) {
            f[v][i] += f[u][i];
        }
        dfsi(v);
    }
}

void dfsj(int u) {
    for(auto v : child[1][u]) {
        for(int i = 0; i < N; i++) {
            f[i][v] += f[i][u];
        }
        dfsj(v);
    }
}

int main() {
    scanf("%d%d", &N, &M);
    for(int i = 0; i < N; i++) {
        for(int j = 0; j <= 1; j++) {
            scanf("%d", &a);
            if(a == 0) root[j] = i; else child[j][--a].push_back(i);
        }
    }

    for(int i = 0; i < M; i++) {
        scanf("%d%d", &r, &s);
        f[--r][--s]++;
    }

    dfsi(root[0]);
    dfsj(root[1]);

    for(int i = 0; i < N; i++) {
        printf("%d\n", f[i][i]);
    }
    return 0;
}

Compilation message

spy.cpp: In function 'int main()':
spy.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     scanf("%d%d", &N, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~
spy.cpp:31:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |             scanf("%d", &a);
      |             ~~~~~^~~~~~~~~~
spy.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         scanf("%d%d", &r, &s);
      |         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1356 KB Output is correct
2 Correct 2 ms 1356 KB Output is correct
3 Correct 1 ms 1356 KB Output is correct
4 Correct 1 ms 1356 KB Output is correct
5 Correct 1 ms 1408 KB Output is correct
6 Correct 1 ms 1356 KB Output is correct
7 Correct 1 ms 1356 KB Output is correct
8 Correct 1 ms 1356 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 16292 KB Output is correct
2 Correct 64 ms 16324 KB Output is correct
3 Correct 61 ms 16060 KB Output is correct
4 Correct 59 ms 16096 KB Output is correct
5 Correct 68 ms 16064 KB Output is correct
6 Correct 69 ms 16076 KB Output is correct
7 Correct 69 ms 16224 KB Output is correct
8 Correct 67 ms 16076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 228 ms 16452 KB Output is correct
2 Correct 165 ms 16308 KB Output is correct
3 Correct 169 ms 16184 KB Output is correct
4 Correct 163 ms 16120 KB Output is correct
5 Correct 208 ms 16220 KB Output is correct
6 Correct 165 ms 16212 KB Output is correct
7 Correct 210 ms 16336 KB Output is correct
8 Correct 226 ms 16324 KB Output is correct