이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |