Problem:
Chinese Postman Problem

For a given weighted undirected graph G(V, E), find the distance of the shortest route that meets the following criteria:

It is a closed cycle where it ends at the same point it starts.

The route must go through every edge at least once.

Input

|V| |E|
s0 t0 d0
s1 t1 d1
:
s|E|-1 t|E|-1 d|E|-1

, where |V| is the number of vertices and |E| is the number of edges in the graph. The graph vertices are named with the numbers 0, 1,..., |V|-1 respectively.

si and ti represent source and target verticess of i-th edge (undirected) and di represents the distance between si and ti (the i-th edge).

Note that there can be multiple edges between a pair of vertices.

Output

Print the shortest distance in a line.

Constraints

2 ≤ |V| ≤ 15

0 ≤ |E| ≤ 1,000

0 ≤ di ≤ 1,000

si ≠ ti

The graph is connected

Sample Input 1

4 4
0 1 1
0 2 2
1 3 3
2 3 4

Sample Output 1

10

Sample Input 2

4 5
0 1 1
0 2 2
1 3 3
2 3 4
1 2 5

Sample Output 2

18

Sample Input 3

2 3
0 1 1
0 1 2
0 1 3

Sample Output 3

7

Solution in C# (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Edge : IComparable
    {
        internal int from, to, weight;

        public Edge(int s, int t, int d)
        {
            from = s;
            to = t;
            weight = d;
        }

        public int CompareTo(object obj)
        {
            Edge other = obj as Edge;

            if (weight != other.weight) return other.weight - weight;   // reverse
            if (from != other.from) return from - other.from;
            else return to - other.to;
        }
    }

    class Program
    {
        static readonly int INFTY = int.MaxValue / 2;

        static void Main(string[] args)
        {
            int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int V = input[0];
            int E = input[1];

            Dictionary<int, List<Edge>> G = new Dictionary<int, List<Edge>>();
            for (int i = 0; i < V; i++) G.Add(i, new List<Edge>());

            for (int i = 0; i < E; i++)
            {
                input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                int s = input[0];
                int t = input[1];
                int d = input[2];

                G[s].Add(new Edge(s, t, d));
                G[t].Add(new Edge(t, s, d));
            }
            Console.WriteLine(ChinesePostman(G));
        }

        static int ChinesePostman(Dictionary<int, List<Edge>> G)
        {
            int V = G.Count, total = 0;
            List<int> odds = new List<int>();

            for (int i = 0; i < V; i++)
            {
                foreach (var e in G[i]) total += e.weight;

                if (G[i].Count % 2 != 0) odds.Add(i);
            }

            total /= 2;
            int n = odds.Count;
            int N = 1 << n;

            int[,] W = new int[n, n];

            for (int u = 0; u < n; u++)
            {
                int s = odds[u];

                int[] dist = new int[V];
                int[] prev = new int[V];

                for (int i = 0; i < V; i++)
                {
                    dist[i] = INFTY;
                    prev[i] = -2;
                }

                dist[s] = 0;

                PriorityQueue<Edge> PQ = new PriorityQueue<Edge>();
                PQ.Enqueue(new Edge(-1, s, 0));

                while (PQ.Count() > 0)
                {
                    Edge e = PQ.Dequeue();

                    if (prev[e.to] != -2) continue;

                    prev[e.to] = e.from;

                    foreach (var f in G[e.to])
                    {
                        int tempWeight = e.weight + f.weight;

                        if (dist[f.to] > tempWeight)
                        {
                            dist[f.to] = tempWeight;

                            PQ.Enqueue(new Edge(f.from, f.to, tempWeight));
                        }
                    }
                }

                for (int v = 0; v < n; v++) W[u, v] = dist[odds[v]];
            }

            int[] dp = Enumerable.Repeat(INFTY, N).ToArray();
            dp[0] = 0;

            for (int S = 0; S < N; S++)
            {
                for (int i = 0; i < n; i++)
                {
                    if ((S & (1 << i)) != 0) continue;

                    for (int j = i + 1; j < n; j++)
                    {
                        if ((S & (1 << j)) != 0) continue;

                        dp[S | (1 << i) | (1 << j)] = Math.Min(dp[S | (1 << i) | (1 << j)], dp[S] + W[i, j]);
                    }
                }
            }

            return total + dp[N - 1];
        }
    }

    class PriorityQueue<T> where T : IComparable
    {
        List<T> heap;
        int size;

        public PriorityQueue()
        {
            heap = new List<T>();
        }

        public void Enqueue(T x)
        {
            heap.Add(x);
            int i = size++;

            while (i > 0)
            {
                int p = (i - 1) / 2;

                if (Compare(heap[p], x) <= 0) break;

                heap[i] = heap[p];
                i = p;
            }
            heap[i] = x;
        }

        public T Dequeue()
        {
            T ret = heap[0];
            T x = heap[--size];

            int i = 0;
            while (i * 2 + 1 < size)
            {
                int a = i * 2 + 1;
                int b = i * 2 + 2;

                if (b < size && Compare(heap[b], heap[a]) < 0)
                    a = b;
                if (Compare(heap[a], x) >= 0)
                    break;

                heap[i] = heap[a];
                i = a;
            }
            heap[i] = x;
            heap.RemoveAt(size);
            return ret;
        }

        public int Count()
        {
            return size;
        }

        private int Compare(T x, T y)
        {
            return y.CompareTo(x);
        }
    }
}