fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. map<int,vector<int>>mp;
  6. int n,m,a,b;
  7. cin>>n>>m;
  8. for(int i=1;i<=m;i++){
  9. cin>>a>>b;
  10. mp[a].push_back(b);
  11. }
  12. for(auto x:mp){
  13. cout<<x.first<<" ----> ";
  14. for(auto l:x.second){
  15. cout<<l<<" ";
  16. }
  17. cout<<endl;
  18. }
  19. int ind[n+1]={0};
  20. int out[n+1]={0};
  21. for(auto x:mp){
  22. vector<int>v=x.second;
  23. out[x.first]=v.size();
  24. for(auto k:x.second){
  25. ind[k]++;
  26. }
  27. }
  28. for(int i=1;i<n+1;i++){
  29. cout<<ind[i]<<" ";
  30. }
  31. cout<<endl;
  32. for(int i=1;i<n+1;i++){
  33. cout<<out[i]<<" ";
  34. }
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5388KB
stdin
10 13
1 2
1 3
6 1
3 6
5 2
5 3
2 3
5 4
4 7
7 5
8 9
9 10
8 10
stdout
1 ----> 2 3 
2 ----> 3 
3 ----> 6 
4 ----> 7 
5 ----> 2 3 4 
6 ----> 1 
7 ----> 5 
8 ----> 9 10 
9 ----> 10 
1 2 3 1 1 1 1 0 1 2 
2 1 1 1 3 1 1 2 1 0