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: Memory Limit Exceeded)

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int V = int.Parse(str[0]);
        int E = int.Parse(str[1]);
        bool[] odd = new bool[V];
        long[,] cost = new long[V,V];
        for(int i=0;i<V;i++){
            for(int j=0;j<V;j++){
                cost[i,j] = 1000000;
            }
        }
        long count = 0;
        for(int i=0;i<E;i++){
            str = Console.ReadLine().Split(' ');
            int s = int.Parse(str[0]);
            int t = int.Parse(str[1]);
            long d = int.Parse(str[2]);
            count += d;
            odd[s] = !odd[s];
            odd[t] = !odd[t];
            cost[s,t] = Math.Min(cost[s,t],d);
            cost[t,s] = cost[s,t];
        }
        List<int> S = new List<int>();
        List<int> T = new List<int>();
        List<long> C = new List<long>();
        for(int i=0;i<V;i++){
            for(int j=i+1;j<V;j++){
                for(int k=0;k<1 << V;k++){
                    S.Add(k);
                    T.Add(k ^ (1 << i) ^ (1 << j));
                    C.Add(cost[i,j]);
                }
            }
        }
        int start = 0;
        for(int i=0;i<V;i++){
            if(odd[i]){
                start += 1 << i;
            }
        }
        Dijkstra D = new Dijkstra(S.ToArray(),T.ToArray(),C.ToArray(),1 << V,start);
        sb.Append((count+D.GetCost(0))+"\n");
    }
}
struct Edge{
    public Vertex v;
    public long cost;
    public Edge(Vertex v0,long c){
        v = v0;
        cost = c;
    }
}
class Vertex{
    public bool finished;
    public List<Vertex> edges;
    public List<long> costs;
    public long cost;
    public void AddEdge(Vertex v,long c){
        edges.Add(v);
        costs.Add(c);
    }
    public Vertex(){
        edges = new List<Vertex>();
        costs = new List<long>();
        cost = -1;
        finished = false;
    }
}
class Dijkstra{
	int E;
	Vertex[] point;
    Vertex S;
    public long GetCost(int i){
        return point[i].cost;
    }
    public Dijkstra(int[] f,int[] t,long[] cost,int n,int s){
        point = new Vertex[n];
        for(int i=0;i<n;i++){
            point[i] = new Vertex();
        }
        E = f.Length;
        for(int i=0;i<E;i++){
            point[f[i]].AddEdge(point[t[i]],cost[i]);
        }
        S = point[s];
        calc();
    }
    void calc(){
        Heap H = new Heap(2*E);
        S.cost = 0;
        H.push(new Edge(S,0));
        while(!H.Empty()){
            Vertex v = H.pop().v;
            if(v.finished){
                continue;
            }
            v.finished = true;
            for(int i=0;i<v.edges.Count;i++){
                Vertex vi = v.edges[i];
                if(vi.cost == -1 || vi.cost > v.costs[i]+v.cost){
                    vi.cost = v.costs[i]+v.cost;
                    H.push(new Edge(vi,vi.cost));
                }
            }
        }
    }
}
class Heap{
    public int size;
    Edge[] obj;
    public Heap(int maxsize){
        size = 0;
        obj = new Edge[maxsize];
    }
    public void push(Edge a){
        int i = size;
        size++;
        while(i > 0){
            int p = (i - 1)/2;
            if(obj[p].cost <= a.cost){
                obj[i] = a;
                break;
            }
            obj[i] = obj[p];
            i = p;
        }
        if(i == 0){
            obj[0] = a;
        }
    }
    public bool Empty(){
        return size == 0;
    }
    public Edge pop(){
        Edge t = obj[0];
        int i = 0;
        size--;
        while(2*i+1 < size){
            int p = 2*i+1;
            if(p+1 < size && obj[p+1].cost < obj[p].cost){
                p++;
            }
            if(obj[p].cost < obj[size].cost){
                obj[i] = obj[p];
                i = p;
            }
            else{
                obj[i] = obj[size];
                break;
            }
        }
        if(2*i+1 >= size){
            obj[i] = obj[size];
        }
        return t;
    }
}