Is this 
using System;
using System.Collections.Generic;

public class TranslatorsDinner
{
    public static void Main()
    {
        var nm = Console.ReadLine().Split();
        int N = int.Parse(nm[0]); 
        int M = int.Parse(nm[1]); 

        if (M % 2 != 0)
        {
            Console.WriteLine("impossible");
            return;
        }

        var languageToTranslators = new List<int>[N];
        for (int i = 0; i < N; i++)
            languageToTranslators[i] = new List<int>();

        for (int i = 0; i < M; i++)
        {
            var langs = Console.ReadLine().Split();
            int lang1 = int.Parse(langs[0]);
            int lang2 = int.Parse(langs[1]);

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

        var matchedTranslators = new bool[M];
        var usedLanguages = new bool[N];
        var pairs = new List<(int, int)>();

        for (int lang = 0; lang < N; lang++)
        {
            if (usedLanguages[lang])
                continue;

            var translators = languageToTranslators[lang];
            var unmatched = new List<int>();

            foreach (int t in translators)
            {
                if (!matchedTranslators[t])
                {
                    unmatched.Add(t);
                }
            }

            if (unmatched.Count >= 2)
            {
                matchedTranslators[unmatched[0]] = true;
                matchedTranslators[unmatched[1]] = true;
                usedLanguages[lang] = true; 
                pairs.Add((unmatched[0], unmatched[1]));
            }
        }

        if (Array.Exists(matchedTranslators, t => !t))
        {
            Console.WriteLine("impossible");
        }
        else
        {
            foreach (var (t1, t2) in pairs)
            {
                Console.WriteLine($"{t1} {t2}");
            }
        }
    }
}
the best way of solving 

It is time again for the annual International Convention for Phonetic Communication. Because there are attendees from all over the world, and they do not all speak the same languages, the organizers have hired translators to help out.

To thank the translators at the end of the conference for their hard work, the organizers want to arrange a dinner at a nice local restaurant. However, the restaurant only has small, two person tables, hence the translators will have to be divided into pairs. As the organizers would like the translators to have a nice evening, they prefer that two translators sitting at the same table are both able to speak the same language. Write a program to help the organizers determine a way to match up the translators in pairs, so that each of the translators speaks a language that the other also speaks.

Input
The first line contains two numbers 
 and 
, the number of languages spoken at the convention, and the number of hired translators respectively (
, 
).

The following 
 lines each describe a translator. Each of these lines contains two integers specifying the two languages that the translator speaks. Languages are identified by integers in the range 
.

Translators are identified by integers in the range 
. Translators are listed in order of increasing identifier (i.e. the first listed translator has identifier 
).

There are no two translators who both speak the same two languages. Translators have been chosen such that any two languages spoken at the conference can be translated into one another, although it may take several translators.

Output
If it is possible to match up all translators such that each pair speaks a common language, output a possible matching: print 
 lines, each line containing the two identifiers of a pair of matched translators. The pairs, as well as the translators within a pair, may be listed in any order.

There may be multiple possible matchings. In that case, print any one of them.

If it is not possible to match up all translators, output a single line containing the word “impossible”.

Sample Input 1	Sample Output 1
5 6
0 1
0 2
1 3
2 3
1 2
4 3
5 3
1 0
2 4
Sample Input 2	Sample Output 2
3 3
0 1
1 2
2 0
impossible
4 6
0 1
1 2
2 3
3 0
0 2
1 3

0 1
2 3
4 5