fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <memory.h>
  5. #include <assert.h>
  6.  
  7. using namespace std;
  8.  
  9. int N, M, graph[1001][1001];
  10. int main() {
  11. scanf("%d", &N);
  12. scanf("%d", &M);
  13. while (M--) {
  14. int u, v;
  15. scanf("%d %d", &u, &v);
  16. graph[u][v] = graph[v][u] = 1;
  17. }
  18. long long diffColor = 0;
  19. for (int i = 1; i <= N; i++) {
  20. int blackCount = 0, redCount = 0;
  21. for (int j = 1; j <= N; j++) {
  22. if (i != j) {
  23. blackCount += !graph[i][j];
  24. redCount += graph[i][j];
  25. }
  26. }
  27. diffColor += blackCount * redCount;
  28. }
  29. assert(diffColor % 2 == 0);
  30. long long sameColor = (long long)N * (N - 1) * (N - 2) / 6 - diffColor / 2;
  31. printf("%lld\n", sameColor);
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0s 19144KB
stdin
Standard input is empty
stdout
0