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 int lli;
lli a, b, c, d, e, f, g, h, parx[2009], pary[2009], root, ans[2009]={}, cnt[2009]={};
vector<lli> D[2009], x[2009];
void DSF(lli u)
{
for(auto v: x[u])
{
cnt[v]++;
}
lli m=u;
while(m!=0)
{
ans[u]+=cnt[m];
m=pary[m];
}
for(auto v: D[u])
{
DSF(v);
}
for(auto v: x[u])
{
cnt[v]--;
}
}
int main()
{
//freopen("test.inp","r",stdin);
cin>>a>>b;
for(int i=1;i<=a;i++)
{
cin>>parx[i]>>pary[i];
if(parx[i]==0)
{
root==i;
}
D[parx[i]].push_back(i);
}
for(int i=1;i<=b;i++)
{
cin>>c>>d;
x[c].push_back(d);
}
DSF(root);
for(int i=1;i<=a;i++)
{
cout<<ans[i]<<endl;
}
}
Compilation message (stderr)
spy.cpp: In function 'int main()':
spy.cpp:36:8: warning: statement has no effect [-Wunused-value]
root==i;
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |