With this code
using System;
using System.Collections.Generic;

public class TranslatorsDinner
{
    static int N, M;
    static List<int>[] languageToTranslators;
    static List<int>[] graph;
    static int[] pair;
    static int[] dist;
    static int INF = int.MaxValue;

    public static void Main(string[] args)
    {
        // Read input
        string[] nm = Console.ReadLine().Split();
        N = int.Parse(nm[0]);
        M = int.Parse(nm[1]);

        // Initialize data structures
        languageToTranslators = new List<int>[N];
        for (int i = 0; i < N; i++) languageToTranslators[i] = new List<int>();

        graph = new List<int>[M];
        for (int i = 0; i < M; i++) graph[i] = new List<int>();

        // Read each translator's languages and populate languageToTranslators
        for (int i = 0; i < M; i++)
        {
            string[] langs = Console.ReadLine().Split();
            int lang1 = int.Parse(langs[0]);
            int lang2 = int.Parse(langs[1]);

            languageToTranslators[lang1].Add(i);
            languageToTranslators[lang2].Add(i);
        }

        // Build the graph by connecting translators who share the same language
        for (int i = 0; i < N; i++)
        {
            foreach (int u in languageToTranslators[i])
            {
                foreach (int v in languageToTranslators[i])
                {
                    if (u != v && !graph[u].Contains(v))
                    {
                        graph[u].Add(v);
                    }
                }
            }
        }

        // Initialize pairing array and distance array for Hopcroft-Karp
        pair = new int[M];
        dist = new int[M];
        Array.Fill(pair, -1);

        // Apply Hopcroft-Karp algorithm to find the maximum matching
        int matching = 0;
        while (BFS())
        {
            for (int u = 0; u < M; u++)
            {
                if (pair[u] == -1 && DFS(u))
                {
                    matching++;
                }
            }
        }

        // Check if we found a perfect matching
        if (matching == M / 2)
        {
            for (int u = 0; u < M; u++)
            {
                if (u < pair[u])
                {
                    Console.WriteLine($"{u} {pair[u]}");
                }
            }
        }
        else
        {
            Console.WriteLine("impossible");
        }
    }

    // BFS part of the Hopcroft-Karp algorithm
    static bool BFS()
    {
        Queue<int> queue = new Queue<int>();
        for (int u = 0; u < M; u++)
        {
            if (pair[u] == -1)
            {
                dist[u] = 0;
                queue.Enqueue(u);
            }
            else
            {
                dist[u] = INF;
            }
        }

        bool found = false;
        while (queue.Count > 0)
        {
            int u = queue.Dequeue();
            if (dist[u] < INF)
            {
                foreach (int v in graph[u])
                {
                    int pairV = pair[v];
                    if (pairV == -1)
                    {
                        found = true;
                    }
                    else if (dist[pairV] == INF)
                    {
                        dist[pairV] = dist[u] + 1;
                        queue.Enqueue(pairV);
                    }
                }
            }
        }
        return found;
    }

    // DFS part of the Hopcroft-Karp algorithm
    static bool DFS(int u)
    {
        if (u != -1)
        {
            foreach (int v in graph[u])
            {
                int pairV = pair[v];
                if (pairV == -1 || (dist[pairV] == dist[u] + 1 && DFS(pairV)))
                {
                    pair[u] = v;
                    pair[v] = u;
                    return true;
                }
            }
            dist[u] = INF;
            return false;
        }
        return true;
    }
}
Why do i get 
0 1
2 4
3 5
and not the correct answer 
5 3
1 0
2 4

When i put in 
5 6
0 1
0 2
1 3
2 3
1 2
4 3