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 <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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |