Language: C

#include <stdio.h>


bool** CreateMatrix(int N) {
    bool** matrix = (bool**) malloc(sizeof(char*) * N);
    for (int i = 0; i < N; ++i)
        matrix[i] = (bool*) malloc(sizeof(char) * 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:4:1: error: unknown type name 'bool'
    4 | bool** CreateMatrix(int N) {
      | ^~~~
main.c:2:1: note: 'bool' is defined in header '<stdbool.h>'; this is probably fixable by adding '#include <stdbool.h>'
    1 | #include <stdio.h>
  +++ |+#include <stdbool.h>
    2 | 
main.c: In function 'CreateMatrix':
main.c:5:5: error: unknown type name 'bool'
    5 |     bool** matrix = (bool**) malloc(sizeof(char*) * N);
      |     ^~~~
main.c:5:5: note: 'bool' is defined in header '<stdbool.h>'; this is probably fixable by adding '#include <stdbool.h>'
main.c:5:22: error: 'bool' undeclared (first use in this function)
    5 |     bool** matrix = (bool**) malloc(sizeof(char*) * N);
      |                      ^~~~
main.c:5:22: note: 'bool' is defined in header '<stdbool.h>'; this is probably fixable by adding '#include <stdbool.h>'
main.c:5:22: note: each undeclared identifier is reported only once for each function it appears in
main.c:5:28: error: expected expression before ')' token
    5 |     bool** matrix = (bool**) malloc(sizeof(char*) * N);
      |                            ^
main.c:7:27: error: expected expression before ')' token
    7 |         matrix[i] = (bool*) malloc(sizeof(char) * N);
      |                           ^
main.c: At top level:
main.c:11:17: error: unknown type name 'bool'
   11 | void ZeroMatrix(bool** matrix, int N) {
      |                 ^~~~
main.c:11:17: note: 'bool' is defined in header '<stdbool.h>'; this is probably fixable by adding '#include <stdbool.h>'
main.c:25:19: error: unknown type name 'bool'
   25 | void DeleteMatrix(bool** matrix, int N) {
      |                   ^~~~
main.c:25: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:35:5: error: unknown type name 'bool'
   35 |     bool** matrix = CreateMatrix(N);
      |     ^~~~
main.c:35:5: note: 'bool' is defined in header '<stdbool.h>'; this is probably fixable by adding '#include <stdbool.h>'
main.c:36:5: error: implicit declaration of function 'ZeroMatrix' [-Wimplicit-function-declaration]
   36 |     ZeroMatrix(matrix, N);
      |     ^~~~~~~~~~
main.c:53:5: error: implicit declaration of function 'DeleteMatrix'; did you mean 'CreateMatrix'? [-Wimplicit-function-declaration]
   53 |     DeleteMatrix(matrix, N);
      |     ^~~~~~~~~~~~
      |     CreateMatrix