Language: C

//#include <iostream>
//#include <algorithm>
//#include <string>

#include <stdio.h>
#include <stdlib.h>

//using namespace std;
//
//bool** CreateMatrix(int N) {
//    bool** matrix = new bool*[N];
//    for (int i = 0; i < N; ++i)
//        matrix[i] = new bool[N];
//    return matrix;
//}

bool** CreateMatrix(int N) {
    bool** matrix = (bool**) malloc(sizeof(bool*) * N);
    for (int i = 0; i < N; ++i)
        matrix[i] = (bool*) malloc(sizeof(bool) * N);
    return matrix;
}

void ZeroMatrix(bool** matrix, int N) {
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            matrix[i][j] = 0;
        }
    }
}

//void DeleteMatrix(bool** matrix, int N) {
//    for (int i = 0; i < N; ++i)
//        delete [] matrix[i];
//    delete [] matrix;
//}

void DeleteMatrix(bool** matrix, int N) {
    for (int i = 0; i < N; ++i)
        free(matrix[i]);
    free(matrix);
}

int main() {
    int N;
    //cin >> N;
    scanf("%d", &N);
    bool** matrix = CreateMatrix(N);
    ZeroMatrix(matrix, N);
    for(int i = 0; i < N; i++) {
        int current;
        //cin >> current;
        scanf("%d", &current);
        matrix[i][current-1] = 1;
    }
    int res = 0;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            if(matrix[i][j] == 1 && matrix[j][i] == 1)
                res++;
        }
    }
    res = res / 2;
    //cout << res << endl;
    printf("%d\n", res);
    DeleteMatrix(matrix, N);
    return 0;
}

Compiler output:
main.c:17:1: error: unknown type name 'bool'
   17 | bool** CreateMatrix(int N) {
      | ^~~~
main.c:7:1: note: 'bool' is defined in header '<stdbool.h>'; this is probably fixable by adding '#include <stdbool.h>'
    6 | #include <stdlib.h>
  +++ |+#include <stdbool.h>
    7 | 
main.c: In function 'CreateMatrix':
main.c:18:5: error: unknown type name 'bool'
   18 |     bool** matrix = (bool**) malloc(sizeof(bool*) * N);
      |     ^~~~
main.c:18:5: note: 'bool' is defined in header '<stdbool.h>'; this is probably fixable by adding '#include <stdbool.h>'
main.c:18:22: error: 'bool' undeclared (first use in this function)
   18 |     bool** matrix = (bool**) malloc(sizeof(bool*) * N);
      |                      ^~~~
main.c:18:22: note: 'bool' is defined in header '<stdbool.h>'; this is probably fixable by adding '#include <stdbool.h>'
main.c:18:22: note: each undeclared identifier is reported only once for each function it appears in
main.c:18:28: error: expected expression before ')' token
   18 |     bool** matrix = (bool**) malloc(sizeof(bool*) * N);
      |                            ^
main.c:20:27: error: expected expression before ')' token
   20 |         matrix[i] = (bool*) malloc(sizeof(bool) * N);
      |                           ^
main.c: At top level:
main.c:24:17: error: unknown type name 'bool'
   24 | void ZeroMatrix(bool** matrix, int N) {
      |                 ^~~~
main.c:24:17: note: 'bool' is defined in header '<stdbool.h>'; this is probably fixable by adding '#include <stdbool.h>'
main.c:38:19: error: unknown type name 'bool'
   38 | void DeleteMatrix(bool** matrix, int N) {
      |                   ^~~~
main.c:38:19: note: 'bool' is defined in header '<stdbool.h>'; this is probably fixable by adding '#include <stdbool.h>'
main.c: In function 'main':
main.c:48:5: error: unknown type name 'bool'
   48 |     bool** matrix = CreateMatrix(N);
      |     ^~~~
main.c:48:5: note: 'bool' is defined in header '<stdbool.h>'; this is probably fixable by adding '#include <stdbool.h>'
main.c:49:5: error: implicit declaration of function 'ZeroMatrix' [-Wimplicit-function-declaration]
   49 |     ZeroMatrix(matrix, N);
      |     ^~~~~~~~~~
main.c:66:5: error: implicit declaration of function 'DeleteMatrix'; did you mean 'CreateMatrix'? [-Wimplicit-function-declaration]
   66 |     DeleteMatrix(matrix, N);
      |     ^~~~~~~~~~~~
      |     CreateMatrix