이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 2e3 + 5;
int n, m;
int tin[2][N], tout[2][N], pf[N][N];
vector<int> g[2][N];
void dfs(int u, int *tin, int *tout, vector<int> *g, int &timer) {
tin[u] = ++timer;
for (int v : g[u]) {
dfs(v, tin, tout, g, timer);
}
tout[u] = timer;
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> m;
array<int, 2> root{};
for (int i = 1; i <= n; ++i) {
array<int, 2> p; cin >> p[0] >> p[1];
for (auto it : {0, 1}) {
if (p[it] == 0) {
root[it] = i;
} else {
g[it][p[it]].push_back(i);
}
}
}
for (auto it : {0, 1}) {
int _ = 0;
dfs(root[it], tin[it], tout[it], g[it], _);
}
auto upd = [&](int a, int b, int x, int y) {
++pf[a][b];
++pf[x + 1][y + 1];
--pf[x + 1][b];
--pf[a][y + 1];
};
while (m--) {
int a, b; cin >> a >> b;
upd(tin[0][a], tin[1][b], tout[0][a], tout[1][b]);
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
pf[i][j] += pf[i - 1][j] + pf[i][j - 1] - pf[i - 1][j - 1];
}
}
for (int i = 1; i <= n; ++i) {
cout << pf[tin[0][i]][tin[1][i]] << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |