# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
202935 | arnold518 | 스파이 (JOI13_spy) | C++14 | 253 ms | 20984 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;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 2000;
const int MAXM = 5e5;
int N, M, A[MAXN+10][MAXN+10];
struct Tree
{
vector<int> adj[MAXN+10];
int in[MAXN+10], out[MAXN+10], cnt=0, root;
void dfs(int now)
{
in[now]=++cnt;
for(int nxt : adj[now]) dfs(nxt);
out[now]=cnt;
}
}TA, TB;
int main()
{
int i, j;
scanf("%d%d", &N, &M);
for(i=1; i<=N; i++)
{
int pa, pb;
scanf("%d%d", &pa, &pb);
if(pa==0) TA.root=i;
else TA.adj[pa].push_back(i);
if(pb==0) TB.root=i;
else TB.adj[pb].push_back(i);
}
TA.dfs(TA.root);
TB.dfs(TB.root);
for(i=1; i<=M; i++)
{
int a, b;
scanf("%d%d", &a, &b);
A[TA.in[a]][TB.in[b]]++;
A[TA.in[a]][TB.out[b]+1]--;
A[TA.out[a]+1][TB.in[b]]--;
A[TA.out[a]+1][TB.out[b]+1]++;
}
for(i=1; i<=N; i++) for(j=1; j<=N; j++) A[i][j]+=A[i-1][j]+A[i][j-1]-A[i-1][j-1];
for(i=1; i<=N; i++) printf("%d\n", A[TA.in[i]][TB.in[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... |