fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define nl '\n'
  6.  
  7. const int N = 2e3 + 5;
  8.  
  9. vector<int> in[N], out[N];
  10.  
  11. set<pair<int, int>> s;
  12.  
  13. void Solve(){
  14. int n, m;
  15. cin>>n>>m;
  16. for(int i = 0; i < m; i++){
  17. int u, v;
  18. cin>>u>>v;
  19. in[v].push_back(u);
  20. out[u].push_back(v);
  21. s.insert({u, v});
  22. }
  23. long long res = 0;
  24. for(int i = 1; i <= n; i++){
  25. for(auto x: in[i]){
  26. for(auto y: out[i]){
  27. if(x == y) continue;
  28. if(s.find({x, y}) == s.end()){
  29. //cout<<x<<" "<<y<<nl;
  30. s.insert({x, y});
  31. res++;
  32. in[y].push_back(x);
  33. out[x].push_back(y);
  34. }
  35. }
  36. }
  37. }
  38. cout<<res<<nl;
  39.  
  40. }
  41. int main(){
  42. ios_base::sync_with_stdio(0); cin.tie(0);
  43. int T = 1;
  44. //cin>>T;
  45. while(T--){
  46. Solve();
  47. }
  48. }
Runtime error #stdin #stdout 0.01s 5392KB
stdin
Standard input is empty
stdout
Standard output is empty