#include <iostream>
#include <cstdio>
#include <cassert>
#include <bitset>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <queue>
#include <numeric>
#include <iomanip>
#define ll long long
using namespace std;
const int MAXN = 2001;
int par1[MAXN],par2[MAXN];
vector<int> tree1[MAXN],tree2[MAXN];
int cnt[MAXN][MAXN];
void dfs(int here,int dad,vector<int> tree[MAXN],int par[MAXN]){
par[here] = dad;
for(auto x:tree[here]){
if(x == dad) continue;
dfs(x,here,tree,par);
}
}
vector<int> g(int here,int par[MAXN]){
vector<int> ret;
while(here != 0){
ret.push_back(here);
here = par[here];
}
return ret;
}
int main(){
ios::sync_with_stdio(false); cin.tie(0);
int n,m; cin >> n >> m;
for(int i = 1; i <= n; i++){
int u,v; cin>>u>>v;
tree1[u].push_back(i);
tree2[v].push_back(i);
}
for(int i=1;i<=m;i++){
int a,b; cin>>a>>b;
cnt[a][b]++;
}
dfs(0,-1,tree1,par1);
dfs(0,-1,tree2,par2);
for(int i=1;i<=n;i++){
vector<int> L = g(i,par1);
vector<int> R = g(i,par2);
int ans = 0;
for(auto x:L)for(auto y:R){
ans += cnt[x][y];
}
cout<<ans<<"\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
888 KB |
Output is correct |
2 |
Correct |
4 ms |
888 KB |
Output is correct |
3 |
Correct |
3 ms |
976 KB |
Output is correct |
4 |
Correct |
2 ms |
976 KB |
Output is correct |
5 |
Correct |
3 ms |
1140 KB |
Output is correct |
6 |
Correct |
2 ms |
1140 KB |
Output is correct |
7 |
Correct |
2 ms |
1292 KB |
Output is correct |
8 |
Correct |
2 ms |
1296 KB |
Output is correct |
9 |
Correct |
2 ms |
1296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1874 ms |
7392 KB |
Output is correct |
2 |
Correct |
1576 ms |
7392 KB |
Output is correct |
3 |
Correct |
7 ms |
7392 KB |
Output is correct |
4 |
Correct |
6 ms |
7392 KB |
Output is correct |
5 |
Correct |
11 ms |
7392 KB |
Output is correct |
6 |
Correct |
8 ms |
7392 KB |
Output is correct |
7 |
Correct |
92 ms |
7564 KB |
Output is correct |
8 |
Correct |
13 ms |
7596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2045 ms |
21584 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |