Problema con Tecnico Pazzo (pazzo)

Salve a tutti, non capisco perché nei test case spunti fuori la voce “Execution killed with signal 11 (could be triggered by violating memory limits)”, qualcuno saprebbe aiutarmi?.
Grazie mille.
Ps. sono un principiante/dilettante.

#include<bits/stdc++.h>

using namespace std;

void solve(int a[], int N){
	int i,j;
	cin >> i >> j;
	for(int h=0;h<N;h++){
		if(a[h] == i){
			a[h] = j;
		}
		else if(a[h] == j){
			a[h] = i;
		}
	}
	
}

main(){
	int N,M;
	cin >> N >> M;
	int a[N];
	a[0] = 0;
	
	for(int i=1;i<N;i++){
		a[i] = a[i-1]+1;
	}
	
	for(int i=0;i<M;i++){
		solve(a,N);
	}
	cout << a[0];
}

The input must come from an input file. The same for the output.
This should work:

    #include <bits/stdc++.h>
    using namespace std;

    void solve(int a[], int N, FILE* fr)
    {
        int i, j;
        assert(2 == fscanf(fr, "%d%d", &i, &j));
        for (int h = 0; h < N; h++) {
            if (a[h] == i) {
                a[h] = j;
            }
            else if (a[h] == j) {
                a[h] = i;
            }
        }
    }

    main()
    {
        FILE *fr, *fw;
        int N, M;
        fr = fopen("input.txt", "r");
        fw = fopen("output.txt", "w");
        assert(2 == fscanf(fr, "%d%d", &N, &M));
        int a[N];
        a[0] = 0;

        for (int i = 1; i < N; i++) {
            a[i] = a[i - 1] + 1;
        }

        for (int i = 0; i < M; i++) {
            solve(a, N, fr);
        }
        fprintf(fw, "%d\n", a[0]);
    }