#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
spy.cpp: In function 'int main()':
spy.cpp:36:8: warning: statement has no effect [-Wunused-value]
root==i;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2172 KB |
Output is correct |
2 |
Correct |
3 ms |
2172 KB |
Output is correct |
3 |
Correct |
0 ms |
2172 KB |
Output is correct |
4 |
Correct |
0 ms |
2172 KB |
Output is correct |
5 |
Correct |
0 ms |
2172 KB |
Output is correct |
6 |
Correct |
0 ms |
2172 KB |
Output is correct |
7 |
Correct |
0 ms |
2172 KB |
Output is correct |
8 |
Correct |
0 ms |
2172 KB |
Output is correct |
9 |
Correct |
0 ms |
2172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
2304 KB |
Output is correct |
2 |
Correct |
6 ms |
2304 KB |
Output is correct |
3 |
Correct |
6 ms |
2172 KB |
Output is correct |
4 |
Correct |
6 ms |
2304 KB |
Output is correct |
5 |
Correct |
13 ms |
2304 KB |
Output is correct |
6 |
Correct |
9 ms |
2308 KB |
Output is correct |
7 |
Correct |
3 ms |
2304 KB |
Output is correct |
8 |
Correct |
6 ms |
2304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
319 ms |
8376 KB |
Output is correct |
2 |
Correct |
356 ms |
10512 KB |
Output is correct |
3 |
Correct |
306 ms |
7536 KB |
Output is correct |
4 |
Correct |
339 ms |
10172 KB |
Output is correct |
5 |
Correct |
303 ms |
8252 KB |
Output is correct |
6 |
Correct |
306 ms |
10492 KB |
Output is correct |
7 |
Correct |
306 ms |
8508 KB |
Output is correct |
8 |
Correct |
333 ms |
8508 KB |
Output is correct |