#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> bool maximize(T &a, const T &b){ return (a < b ? a = b, 1 : 0); }
template<class T> bool minimize(T &a, const T &b){ return (a > b ? a = b, 1 : 0); }
#define fi first
#define se second
#define pb push_back
#define ii pair<int, int>
#define all(x) x.begin(), x.end()
#define TASK "nonsense"
/// end of template ///
const int N = 2e3 + 5;
const int M = N*2;
int n,m;
struct company
{
int st[N],en[N],tg,n,par[N],root;
vector<int> adj[N];
company()
{
tg=0;
}
void dfs(int u, int pa)
{
st[u]=++tg;
for(int v : adj[u]) if(v!=pa)
{
dfs(v,u);
}
en[u]=++tg;
}
void work(int _n)
{
n=_n;
for(int u=1;u<=n;++u)
{
int v=par[u];
if(v==0)
{
root=u;
continue;
}
adj[u].pb(v);
adj[v].pb(u);
}
dfs(root,-1);
}
} joi,ioi;
int p[M][M];
void addRec(int b, int t, int l, int r)
{
++p[b][l];
--p[b][r+1];
--p[t+1][l];
++p[t+1][r+1];
}
void solve()
{
cin>>n>>m;
for(int i=1;i<=n;++i) cin>>joi.par[i]>>ioi.par[i];
joi.work(n);
ioi.work(n);
while(m--)
{
int u,v; cin>>u>>v;
addRec(joi.st[u],joi.en[u],ioi.st[v],ioi.en[v]);
}
for(int i=1;i<M;++i) for(int j=1;j<M;++j) p[i][j]+=p[i-1][j]+p[i][j-1]-p[i-1][j-1];
for(int i=1;i<=n;++i) cout<<p[joi.st[i]][ioi.st[i]]<<'\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen(TASK".inp","r",stdin);
// freopen(TASK".out","w",stdout);
int testcase=1;
// cin>>testcase;
while (testcase--)
solve();
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... |