이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define ll long long
#define vt vector
#define pb push_back
#define fi first
#define se second
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define pii pair<int, int>
#define pll pair<ll, ll>
//#define int long long
typedef unsigned long long ull;
const int mxn = 2e3, mxm = 5e5;
bitset<mxm>ioi[mxn + 1], joi[mxn + 1];
int p[mxn + 1], q[mxn + 1];
int n, m, rootj, rooti;
vt<int>adj[mxn + 1], g[mxn + 1];
void dfs(int s, int pre){
for(auto i: adj[s]){
joi[i] |= joi[s];
dfs(i, s);
}
}
void dfs2(int s, int pre){
for(auto i: g[s]){
ioi[i] |= ioi[s];
dfs2(i, s);
}
}
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> p[i];
if(p[i])adj[p[i]].pb(i);
else rootj = i;
cin >> q[i];
if(q[i])g[q[i]].pb(i);
else rooti = i;
}
for(int i = 0; i < m; i++){
int r, b; cin >> r >> b;
joi[r][i] = 1; ioi[b][i] = 1;
}
dfs(rootj, -1); dfs2(rooti, -1);
for(int i = 1; i <= n; i++){
cout << (joi[i] & ioi[i]).count() << "\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... |