# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
34034 | ToMoClone | 스파이 (JOI13_spy) | C++14 | 233 ms | 17952 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.
/*input
3 4
0 2
1 0
2 2
1 1
2 1
2 3
3 2
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 2007;
int startI[N], finishI[N], par[N], ans[N][N], n, m, rootI, cnt;
vector<int> childI[N];
void dfs(int u){
startI[u] = ++cnt;
for(auto v:childI[u]) dfs(v);
finishI[u] = cnt + 1;
}
int main(){
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; ++i){
int a, b; scanf("%d%d", &a, &b);
childI[b].push_back(i);
if(b == 0) rootI = i;
par[i] = a;
}
dfs(rootI);
for(int i = 1; i <= m; ++i){
int a, b; scanf("%d%d", &a, &b);
++ans[a][startI[b]];
--ans[a][finishI[b]];
}
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
ans[i][j] += ans[i][j - 1];
for(int i = 1; i <= n; ++i){
int k = i, res = 0;
while(k != 0) res += ans[k][startI[i]], k = par[k];
printf("%d\n", res);
}
}
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... |