topic portal
ideas
In fact, this question does not require knowledge of graphs at all.
Count the in-degree and out-degree of each point and check the data for duplicates.
code
#include <iostream>
using namespace std;
int n,m;
int din[1001],dout[1001];
bool vis[1001][1001];
int main(int argc, char const *argv[]) {
cin>>n>>m;
for(int i=0;i<m;i++){
int a,b;
cin>>a>>b;
if(!vis[a][b]){
vis[a][b]=true;
din[b]++;
dout[a]++;
}
}
for(int i=0;i<n;i++){
cout<<din[i]-dout[i]<<endl;
}
return 0;
}