# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
112492 | njchung99 | 스파이 (JOI13_spy) | C++14 | 216 ms | 31968 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<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
int dp[2010][2010];
int sum[2010][2010];
int p[2010];
int p1[2010];
int func(int here, int here1)
{
if (here == 0 || here1 == 0)return 0;
int &ret = dp[here][here1];
if (ret != -1)return ret;
ret =sum[here][here1]+func(p[here],here1)+func(here,p1[here1])-func(p[here],p1[here]);
return ret;
}
int main()
{
memset(dp, -1, sizeof(dp));
int n, m;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
int q, w;
scanf("%d %d", &q, &w);
p[i] = q; p1[i] = w;
}
for (int i = 1; i <= m; i++) {
int q, w;
scanf("%d %d", &q, &w);
sum[q][w]++;
}
for (int i = 1; i <= n; i++) {
printf("%d\n", func(i, i));
}
}
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... |