# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
448228 | hizuna | 스파이 (JOI13_spy) | C++17 | 228 ms | 16452 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |