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 = 2005;
int par1[MAXN],par2[MAXN];
vector<int> tree1[MAXN],tree2[MAXN];
int cnt[MAXN][MAXN];
int pcnt[MAXN][MAXN]; //[노드,path]
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 tot = 0;
void dfs2(int here,int root,int dad,vector<int> tree[MAXN]){
pcnt[root][here] = tot;
for(int i=0;i<tree[here].size();i++){
int there = tree[here][i];
if(there == dad) continue;
tot += cnt[root][there];
dfs2(there,root,here,tree);
tot -= cnt[root][there];
}
}
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++){
tot = 0;
dfs2(0,i,-1,tree2);
}
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){
ans += pcnt[x][i];
}
cout<<ans<<"\n";
}
return 0;
}
Compilation message (stderr)
spy.cpp: In function 'void dfs2(int, int, int, std::vector<int>*)':
spy.cpp:44:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<tree[here].size();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... |