int dfs(const vector<vector<int> > &vv, vector<bool> &visited, int s, int path, int &Min)
{
    bool flag = false;
    for(int i = 0; i < vv[s].size(); ++i)
    {
        if(!visited[i])
        {
            flag = true;
            visited[i] = true;
            dfs(vv, visited, i, path+vv[s][i], Min);
            visited[i] = false;
        }
    }
    if(!flag && Min > path)
       Min = path;
}

int main()
{
	int Min = INT_MAX;
    vector<vector<int> > vv;
    vv.push_back({0,1,2,3});
    vv.push_back({1,0,4,5});
    vv.push_back({2,4,0,2});
    vv.push_back({3,5,2,0});
    vector<bool> visited(vv.size());
    for(int i = 0; i < vv.size(); ++i)
    {
        visited[i] = true;
        dfs(vv, visited, i, 0, Min);
        visited[i] = false;
    }
    cout << Min << endl;
    return 0;
}