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>
#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... |