Problem:
Problem I
Routing a Marathon Race
As a member of the ICPC (Ibaraki Committee of Physical Competitions), you are responsible for planning the route of a marathon event held in the City of Tsukuba. A great number of runners, from beginners to experts, are expected to take part.
You have at hand a city map that lists all the street segments suited for the event and all the junctions on them. The race is to start at the junction in front of Tsukuba High, and the goal is at the junction in front of City Hall, both of which are marked on the map.
To avoid congestion and confusion of runners of divergent skills, the route should not visit the same junction twice. Consequently, although the street segments can be used in either direction, they can be included at most once in the route. As the main objective of the event is in recreation and health promotion of citizens, time records are not important and the route distance can be arbitrarily decided.
A number of personnel have to be stationed at every junction on the route. Junctions
adjacent
to them, i.e., junctions connected directly by a street segment to the junctions on the route, also need personnel staffing to keep casual traffic from interfering the race. The same number of personnel is required when a junction is on the route and when it is adjacent to one, but different junctions require different numbers of personnel depending on their sizes and shapes, which are also indicated on the map.
The municipal authorities are eager in reducing the costs including the personnel expense for
events of this kind. Your task is to write a program that plans a route with the minimum
possible number of personnel required and outputs that number.
Input
The input consists of a single test case representing a summary city map, formatted as follows.
$n$ $m$
$c_1$
...
$c_n$
$i_1$ $j_1$
...
$i_m$ $j_m$
The first line of a test case has two positive integers, $n$ and $m$. Here, $n$ indicates the number of junctions in the map $(2 \leq n \leq 40)$, and $m$ is the number of street segments connecting adjacent junctions. Junctions are identified by integers 1 through $n$.
Then comes $n$ lines indicating numbers of personnel required. The $k$-th line of which, an integer $c_k$ $(1 \leq c_k \leq 100)$, is the number of personnel required for the junction $k$.
The remaining $m$ lines list street segments between junctions. Each of these lines has two integers $i_k$ and $j_k$, representing a segment connecting junctions $i_k$ and $j_k$ $(i_k \ne j_k)$. There is at most one street segment connecting the same pair of junctions.
The race starts at junction 1 and the goal is at junction $n$. It is guaranteed that there is at least one route connecting the start and the goal junctions.
Output
Output an integer indicating the minimum possible number of personnel required.
Figure I.1. The Lowest-Cost Route for Sample Input 1
Figure I.1 shows the lowest-cost route for Sample Input 1. The arrows indicate the route and the circles 
...(truncated)

Submitted solutions:

code_snippet: #line 2 "cp-library/src/cp-template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull  = unsigned long long;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
template < class T > bool chmin(T& a, T b) { if(a > b) { a = b; return true; } return false; }
template < class T > bool chmax(T& a, T b) { if(a < b) { a = b; return true; } return false; }
template < class T, class U > T ceil (T x, U y) { return (x > 0 ? (x + y - 1) / y :           x / y); }
template < class T, class U > T floor(T x, U y) { return (x > 0 ?           x / y : (x - y + 1) / y); }
int popcnt(i32 x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(i64 x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }

#line 2 "cp-library/src/utility/rep_itr.hpp"
template < class T > struct itr_rep {
    T i, d;
    constexpr itr_rep(const T i) noexcept : i(i), d(1) {}
    constexpr itr_rep(const T i, const T d) noexcept : i(i), d(d) {}
    void operator++() noexcept { i += d; }
    constexpr int operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr_rep x) const noexcept { return d > 0 ? i < x.i : i > x.i; }
};

template < class T > struct rep {
    const itr_rep< T > s, t;
    constexpr rep(const T t) noexcept : s(0), t(t) {}
    constexpr rep(const T s, const T t) noexcept : s(s), t(t) {}
    constexpr rep(const T s, const T t, const T d) noexcept : s(s, d), t(t, d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};

template < class T > struct revrep {
    const itr_rep < T > s, t;
    constexpr revrep(const T t) noexcept : s(t - 1, -1), t(-1, -1) {}
    constexpr revrep(const T s, const T t) noexcept : s(t - 1, -1), t(s - 1, -1) {}
    constexpr revrep(const T s, const T t, const T d) noexcept : s(t - 1, -d), t(s - 1, -d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};
#line 3 "cp-library/src/utility/io.hpp"

/* 128bit integer */
istream& operator>>(istream& is, i128& x) {
    std::string s; is >> s;
    int pm = (s[0] == '-');
    x = 0;
    for(int i : rep(pm, int(s.size()))) x = x * 10 + (s[i] - '0');
    if(pm) x *= -1;
    return is;
}
ostream& operator<<(ostream& os, const i128& x) {
    if(x == 0) return os << '0';
    i128 y = x;
    if(y < 0) { os << '-'; y *= -1; }
    std::vector<int> ny;
    while(y > 0) { ny.push_back(y % 10); y /= 10; }
    for(int i : revrep(ny.size())) os << ny[i];
    return os;
}

template < class S, class T > istream& operator>>(istream& is,       std::pair< S, T >& x) { is >> x.first        >> x.second; return is; }
template < class S, class T > ostream& operator<<(ostream& os, const std::pair< S, T >& x) { os << x.first << " " << x.second; return os; }

namespace scanner {
    struct sca {
        template < class T > operator T() {
            T s; std::cin >> s; return s;
        }
    };
    struct vec {
        int n;
        vec(int n) : n(n) {}
        template < class T > operator std::vector< T >() {
            std::vector< T > v(n);
            for(T& x : v) std::cin >> x;
            return v;
        }
    };
    struct mat {
        int h, w;
        mat(int h, int w) : h(h), w(w) {}
        template < class T > operator std::vector< std::vector< T > >() {
            std::vector m(h, std::vector< T >(w));
            for(std::vector< T >& v : m) for(T& x : v) std::cin >> x;
            return m;
        }
    };
    struct speedup {
        speedup() {
            std::cin.tie(0);
            std::ios::sync_with_stdio(0);
        }
    } speedup_instance;
}
scanner::sca in() { return scanner::sca(); }
scanner::vec in(int n) { return scanner::vec(n); }
scanner::mat in(int h, int w) { return scanner::mat(h, w); }

namespace printer {
    void precision(int d) { std::cout << std::fixed << std::setprecision(d); }
    void flush() { std::cout.flush(); }
}

template < class T >
ostream& operator<<(ostream& os, const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) { os << a[i]; if(i != n - 1) os << ' '; }
    return os;
}

int print() { std::cout << '\n'; return 0; }
template < class head, class... tail > int print(head&& h, tail&&... t) {
    std::cout << h; if(sizeof...(tail)) std::cout << ' ';
    return print(std::forward<tail>(t)...);
}
template < class T > int print_n(const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) std::cout << a[i] << "\n";
    return 0;
}


#line 2 "cp-library/src/utility/key_val.hpp"

template < class K, class V >
struct key_val {
    K key; V val;
    key_val() {}
    key_val(K key, V val) : key(key), val(val) {}
    template < std::size_t Index >
    std::tuple_element_t< Index, key_val >& get() {
        if constexpr (Index == 0) return key;
        if constexpr (Index == 1) return val;
    }
};

namespace std {

template < class K, class V > struct tuple_size < key_val< K, V > > : integral_constant< size_t, 2 > {};
template < class K, class V > struct tuple_element < 0, key_val< K, V > > { using type = K; };
template < class K, class V > struct tuple_element < 1, key_val< K, V > > { using type = V; };

}
#line 2 "cp-library/src/utility/vec_op.hpp"
template < class T > key_val< int, T > max_of(const vector< T >& a) {
    int i = std::max_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class T > key_val< int, T > min_of(const vector< T >& a) {
    int i = std::min_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class S, class T > S sum_of(const vector< T >& a) {
    S sum = 0;
    for(const T x : a) sum += x;
    return sum;
}
template < class S, class T > vector< S > freq_of(const vector< T >& a, T L, T R) {
    vector< S > res(R - L, S(0));
    for(const T x : a) res[x - L] += 1;
    return res;
}
template < class S, class T > struct prefix_sum {
    vector< S > s;
    prefix_sum(const vector< T >& a) : s(a) {
        s.insert(s.begin(), S(0));
        for(int i : rep(a.size())) s[i + 1] += s[i];
    }
    // [L, R)
    S sum(int L, int R) { return s[R] - s[L]; }
};
#line 3 "cp-library/src/utility/heap.hpp"

template < class T > using heap_min = std::priority_queue< T, std::vector< T >, std::greater< T > >;
template < class T > using heap_max = std::priority_queue< T, std::vector< T >, std::less< T > >;

#line 27 "cp-library/src/cp-template.hpp"

#line 1 "cp-library/src/algorithm/bin_search.hpp"
template < class T, class F >
T bin_search(T ok, T ng, F f) {
    while(abs(ng - ok) > 1) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}

template < class T, class F >
T bin_search_real(T ok, T ng, F f, int step = 80) {
    while(step--) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}
#line 2 "cp-library/src/algorithm/argsort.hpp"

template < class T > std::vector< int > argsort(const std::vector< T > &a) {
    std::vector< int > ids((int)a.size());
    std::iota(ids.begin(), ids.end(), 0);
    std::sort(ids.begin(), ids.end(), [&](int i, int j) {
        return a[i] < a[j] || (a[i] == a[j] && i < j);
    });
    return ids;
}
#line 1 "macro.hpp"
namespace macro {

using size_type = int;
template < class container > void  sort(container& a) { std::sort(std:: begin(a), std:: end(a)); }
template < class container > void rsort(container& a) { std::sort(std::rbegin(a), std::rend(a)); }
template < class container > void reverse(container& a) { std::reverse(std::begin(a), std::end(a)); }
template < class container > void unique(container& a) {
    std::sort(std::begin(a), std::end(a));
    a.erase(std::unique(std::begin(a), std::end(a)), std::end(a));
}
template < class container > container  sorted(const container& a) { container b = a;  sort(b); return std::move(b); }
template < class container > container rsorted(const container& a) { container b = a; rsort(b); return std::move(b); }
template < class container, class compare > void sort(container& a, const compare& cmp) { std::sort(std::begin(a), std::end(a), cmp); }
template < class container, class compare > container sorted(const container& a, const compare& cmp) { container b = a; sort(b, cmp); return std::move(b); }
template < class container, class value > size_type lower_bound(const container& a, const value& x) { return std::lower_bound(std::begin(a), std::end(a), x) - std::begin(a); }
template < class container, class value > size_type upper_bound(const container& a, const value& x) { return std::upper_bound(std::begin(a), std::end(a), x) - std::begin(a); }

const std::vector<std::pair<size_type, size_type>> dir4 = { {+1,  0}, {-1,  0}, { 0, +1}, { 0, -1} };
const std::vector<std::pair<size_type, size_type>> dir8 = { {-1, -1}, {-1,  0}, {-1, +1}, { 0, -1}, { 0, +1}, {+1, -1}, {+1,  0}, {+1, +1} };

#ifdef _DEBUG
#define debug(x) std::cout << "[" << __LINE__ << "] " << #x << ": " << x << std::endl
#else
#define debug(x)
#endif

template < class container > void concat(container& a, const container& b) {
    a.insert(std::end(a), std::begin(b), std::end(b));
}
std::vector<size_type> iota(const size_type n) {
    std::vector<size_type> I(n);
    std::iota(std::begin(I), std::end(I), 0);
    return I;
}
template < class container > std::vector<size_type> sort_idx(const container& a) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return a[i] < a[j] or (a[i] == a[j] and i < j); });
    return I;
}
template < class container, class compare > std::vector<size_type> sort_idx(const container& a, const compare& cmp) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return cmp(a[i], a[j]) or (a[i] == a[j] and i < j); });
    return std::move(I);
}

struct grid {
    using size_type = int;
    size_type H, W;
    grid(const size_type H, const size_type W) : H(H), W(W) {}
    bool contains(const size_type i, const size_type j) {
        return 0 <= i and i < H and 0 <= j and j < W;
    }
};

} // namespace macro

using namespace macro;
#line 3 "B.cpp"

int main() {
    int n = in(), m = in();
    vector<int> c = in(n);
    vector<vector<int>> g(n);
    for(int i : rep(m)) {
        int u = in(), v = in(); u--, v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    auto dfs = [&](auto self, i64 S, int u) -> int {
        int cost = c[u];
        i64 T = S | (i64(1) << u);
        for(int v : g[u]) {
            if(!(S & (i64(1) << v))) {
                cost += c[v];
                T |= i64(1) << v;
            }
        }
        if(u == n - 1) return cost;

        int ans = 1e9;
        for(int v : g[u]) {
            if(!(S & (i64(1) << v))) {
                cost -= c[v];
                T ^= i64(1) << v;
                chmin(ans, cost + self(self, T, v));
                cost += c[v];
                T ^= i64(1) << v;
            }
        }
        return ans;
    };

    print(dfs(dfs, 0, 0));
}
accuracy: 1
time_ms: 10
memory_kb: 3528
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define per(i, n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define per2(i, l, r) for (int i = (r)-1; i >= (l); i--)
#define each(e, x) for (auto &e : x)
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define eb emplace_back
#define MM << ' ' <<
#define TT template <typename T>
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

TT bool chmin(T &x, T y) { return x > y ? (x = y, true) : false; }
TT bool chmax(T &x, T y) { return x < y ? (x = y, true) : false; }

TT using minheap = priority_queue<T, vector<T>, greater<T>>;
TT using maxheap = priority_queue<T>;

TT void print(vector<T> v, T x = 0) {
    int n = sz(v);
    rep(i, n) cout << v[i] + x << (i == n - 1 ? '\n' : ' ');
    if (n == 0) cout << '\n';
}

TT void printn(vector<T> v, T x = 0) {
    int n = sz(v);
    rep(i, n) cout << v[i] + x << '\n';
}

TT void rearrange(vector<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), end(v));
}

TT int lb(vector<T> &v, T x) { return lower_bound(all(v), x) - begin(v); }
TT int ub(vector<T> &v, T x) { return upper_bound(all(v), x) - begin(v); }

const int inf = (1 << 30) - 1;
const ll INF = (1LL << 60) - 1;

struct io_setup {
    io_setup() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(15);
    }
} io_setup;

using ld = long double;
using comp = complex<ld>;

struct FFT {
    const ld pi = acos(-1.0);
    vector<comp> r, ir;

    FFT() {
        r.resize(30), ir.resize(30);
        rep(i, 30) {
            r[i] = -polar(ld(1), pi / (1 << (i + 1)));
            ir[i] = -polar(ld(1), -pi / (1 << (i + 1)));
        }
    }

    vector<comp> to_comp(vector<ll> a) {
        int n = sz(a);
        vector<comp> b(n);
        rep(i, n) b[i] = comp(a[i], 0);
        return b;
    }

    vector<ll> to_ll(vector<comp> a) {
        int n = sz(a);
        vector<ll> b(n);
        rep(i, n) b[i] = round(a[i].real());
        return b;
    }

    void fft(vector<comp> &a) {
        int n = sz(a);
        for (int k = n; k >>= 1;) {
            comp w = 1;
            for (int s = 0, t = 0; s < n; s += 2 * k) {
                for (int i = s, j = s + k; i < s + k; i++, j++) {
                    comp x = a[i], y = w * a[j];
                    a[i] = x + y, a[j] = x - y;
                }
                w *= r[__builtin_ctz(++t)];
            }
        }
    }

    void ifft(vector<comp> &a) {
        int n = sz(a);
        for (int k = 1; k < n; k <<= 1) {
            comp w = 1;
            for (int s = 0, t = 0; s < n; s += 2 * k) {
                for (int i = s, j = s + k; i < s + k; i++, j++) {
                    comp x = a[i], y = a[j];
                    a[i] = x + y, a[j] = w * (x - y);
                }
                w *= ir[__builtin_ctz(++t)];
            }
        }
        rep(i, n) a[i] /= n;
    }

    vector<ll> convolve(vector<ll> a, vector<ll> b) {
        if (empty(a) || empty(b)) return {};
        int k = sz(a) + sz(b) - 1, n = 1;
        while (n < k) n <<= 1;
        a.resize(n), b.resize(n);
        vector<comp> A = to_comp(a), B = to_comp(b);
        fft(A), fft(B);
        rep(i, n) A[i] *= B[i];
        ifft(A);
        a = to_ll(A);
        a.resize(k);
        return a;
    }
};

FFT fft;
const int n = 1 << 11;

vector<vector<comp>> fft_2D(vector<vector<ll>> a) {
    a.resize(n);
    rep(i, n) a[i].resize(n, 0);
    vector<vector<comp>> ret(n);
    rep(i, n) ret[i] = fft.to_comp(a[i]);
    rep(i, n) fft.fft(ret[i]);
    rep(j, n) {
        vector<comp> tmp(n);
        rep(i, n) tmp[i] = ret[i][j];
        fft.fft(tmp);
        rep(i, n) ret[i][j] = tmp[i];
    }
    return ret;
}

vector<vector<ll>> ifft_2D(vector<vector<comp>> a) {
    rep(j, n) {
        vector<comp> tmp(n);
        rep(i, n) tmp[i] = a[i][j];
        fft.ifft(tmp);
        rep(i, n) a[i][j] = tmp[i];
    }
    rep(i, n) fft.ifft(a[i]);
    vector<vector<ll>> ret(n);
    rep(i, n) ret[i] = fft.to_ll(a[i]);
    return ret;
}

vector<vector<ll>> convolve_2D(vector<vector<ll>> a, vector<vector<ll>> b) {
    auto A = fft_2D(a), B = fft_2D(b);
    rep(i, n) rep(j, n) A[i][j] *= B[i][j];
    return ifft_2D(A);
}

int flg(ll x, int t) { return (x >> t) & 1; }

int main() {
    int N, M;
    cin >> N >> M;

    vector<int> c(N);
    rep(i, N) cin >> c[i];

    vector<ll> es(N, 0);
    rep(i, M) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        es[u] |= (1LL << v);
        es[v] |= (1LL << u);
    }

    int ans = inf;

    auto calc = [&](ll used) {
        ll S = used;
        rep(i, N) {
            if (flg(used, i)) S |= es[i];
        }
        int sum = 0;
        rep(i, N) {
            if (flg(S, i)) sum += c[i];
        }
        return sum;
    };

    auto dfs = [&](auto &&dfs, ll used, ll ng, int now) -> void {
        if (now == N - 1) {
            chmin(ans, calc(used));
            return;
        }
        rep(i, N) {
            if (!flg(es[now], i) || flg(used, i) || flg(ng, i)) continue;
            ll nused = used | (1LL << i);
            ll nng = ng | es[now];
            dfs(dfs, nused, nng, i);
        }
    };

    dfs(dfs, 1, 0, 0);
    cout << ans << '\n';
}
accuracy: 1
time_ms: 90
memory_kb: 3836
final_rank: 15

code_snippet: #include<bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define per(i, n) for(int i = (n)-1; i >= 0; i--)
#define rep2(i, l, r) for(int i = (l); i < (r); i++)
#define per2(i, l, r) for(int i = (r)-1; i >= (l); i--)
#define each(e, x) for(auto &e : x)
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define eb emplace_back
#define MM << ' ' <<
#define TT template<typename T>
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

TT bool chmin(T &x, T y) { return x > y ? (x = y, true) : false; }

TT bool chmax(T &x, T y) { return x < y ? (x = y, true) : false; }

TT using minheap = priority_queue<T, vector<T>, greater<T>>;
TT using maxheap = priority_queue<T>;

TT void print(vector<T> v, T x = 0) {
    int n = sz(v);
    rep(i, n) cout << v[i] + x << (i == n - 1 ? '\n' : ' ');
    if (n == 0) cout << '\n';
}

TT void printn(vector<T> v, T x = 0) {
    int n = sz(v);
    rep(i, n) cout << v[i] + x << '\n';
}

TT void rearrange(vector<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), end(v));
}

TT int lb(vector<T> &v, T x) { return lower_bound(all(v), x) - begin(v); }

TT int ub(vector<T> &v, T x) { return upper_bound(all(v), x) - begin(v); }

const int inf = (1 << 30) - 1;
const ll INF = (1LL << 60) - 1;

struct io_setup {
    io_setup() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(15);
    }
} io_setup;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> c(n);
    rep(i, n) cin >> c[i];
    vector<vector<int>> g(n);
    vector<ll> ls(n, 0);
    rep(i, m) {
        int u, v;
        cin >> u >> v, u--, v--;
        g[u].eb(v), g[v].eb(u);
        ls[u] |= 1LL << v, ls[v] |= 1LL << u;
    }
    rep(i, n) ls[i] |= 1LL << i;
    int ans = 1e9;
    auto dfs = [&](int now, ll ng, auto &&dfs) ->void {
        if (now == n - 1) {
            ng |= ls[now];
            int sum = 0;
            rep(i, n) if (ng >> i & 1) sum += c[i];
            chmin(ans, sum);
            return;
        }
        each(e, g[now]) {
            if (!(ng >> e & 1))
                dfs(e, ng | ls[now], dfs);
        }
    };
    dfs(0, 0, dfs);
    cout << ans << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3472
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=1<<30;

int cost[43];
ll mask[43];

vector<int> G[43];
bool hen[43][43];

vector<int> trail;
int ans=INF;
int N;

void DFS(int u){
    if(u==N-1){
        ll S=0;
        for(int x:trail) S|=mask[x];
        S|=mask[N-1];
        
        int sum=0;
        for(int i=0;i<N;i++){
            if(S&(1LL<<i)) sum+=cost[i];
        }
        
        chmin(ans,sum);
        return;
    }
    
    for(int to:G[u]){
        bool ok=true;
        for(int mae:trail){
            if(hen[mae][to]) ok=false;
            if(mae==to) ok=false;
        }
        if(ok){
            trail.push_back(u);
            DFS(to);
            trail.pop_back();
        }
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int M;cin>>N>>M;
    for(int i=0;i<N;i++){
        cin>>cost[i];
    }
    
    for(int i=0;i<M;i++){
        int a,b;cin>>a>>b;a--;b--;
        hen[a][b]=hen[b][a]=true;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    for(int i=0;i<N;i++){
        mask[i]|=(1LL<<i);
        for(int to:G[i]) mask[i]|=(1LL<<to);
    }
    
    DFS(0);
    
    cout<<ans<<endl;
}
accuracy: 1
time_ms: 60
memory_kb: 3484
final_rank: 13

code_snippet: #line 1 "a.cpp"
// cSpell:disable
/*	author:  Kite_kuma
	created: 2022.10.23 16:47:19 */

#line 2 "SPJ-Library/template/kuma.hpp"

#line 2 "SPJ-Library/template/basic_func.hpp"

#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>

template <class T0, class T1, class T2>
inline bool in_range(T0 x, T1 lef, T2 rig) {
	return ((lef <= x) && (x < rig));
}

template <class T>
inline bool chmin(T &a, T b) {
	if(a > b) {
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b) {
	if(a < b) {
		a = b;
		return true;
	}
	return false;
}

void Yes(bool flag = true) { std::cout << (flag ? "Yes" : "No") << '\n'; }
void YES(bool flag = true) { std::cout << (flag ? "YES" : "NO") << '\n'; }

template <class T>
void drop(T answer) {
	std::cout << answer << '\n';
	exit(0);
}

template <class T>
void vout(std::vector<T> const &v, bool vertically = 0) {
	if(vertically) {
		for(auto const &a : v) {
			std::cout << a << '\n';
		}
		return;
	}
	for(auto it = v.begin(); it != v.end(); it++) {
		std::cout << (*it);
		if(it != v.end() - 1) {
			std::cout << ' ';
		}
	}
	std::cout << '\n';
	return;
}

inline void print() { std::cout << '\n'; }
template <class T>
inline void print(const T &x) {
	std::cout << x << '\n';
	return;
}
template <typename Head, typename... Tail>
void print(const Head &H, const Tail &... T) {
	std::cout << H << " ";
	print(T...);
}

template <class T>
void add(std::vector<T> &v, T value) {
	for(auto &a : v) a += value;
	return;
}

template <class T>
T greatest_lower_multiple(T x, T d) {
	if(d == 0) return 0;
	if(d < 0) d *= -1;
	T y = x % d;
	if(y < 0) y += d;
	return x - y;
}

template <class T>
T least_upper_multiple(T x, T d) {
	return -greatest_lower_multiple(-x, d);
}

// ceil(a / b);
template <class T>
T dup(T a, T b) {
	assert(b);
	if(b < 0) {
		a *= -1;
		b *= -1;
	}
	return least_upper_multiple(a, b) / b;
}

long long pow_ll(long long a, long long n) {
	assert(n >= 0LL);
	if(n == 0) return 1LL;
	if(a == 0) return 0LL;
	if(a == 1) return 1LL;
	if(a == -1) return (n & 1LL) ? -1LL : 1LL;
	long long res = 1;
	while(n > 1LL) {
		if(n & 1LL) res *= a;
		a *= a;
		n >>= 1;
	}
	return res * a;
}

long long modpow(long long a, long long n, long long mod) {	 // a^n mod
	assert(n >= 0 && mod);
	if(mod == 1) return 0LL;
	long long res = 1;
	a %= mod;
	while(n > 0) {
		if(n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res < 0 ? res + mod : res;
}

// return x which satisfies a * x % mod == gcd(a, mod)
// not (mod | a)
long long modinv(long long a, const long long mod) {
	long long b = mod, u = 1, v = 0;
	while(b) {
		long long t = a / b;
		a -= t * b;
		std::swap(a, b);
		u -= t * v;
		std::swap(u, v);
	}
	u %= mod;
	if(u < 0) u += mod;
	return u;
}

template <class T>
int lb(const std::vector<T> &a, const T x) {
	return (int)std::distance(a.begin(), std::lower_bound(a.begin(), a.end(), x));
}
template <class T>
int ub(const std::vector<T> &a, const T x) {
	return (int)std::distance(a.begin(), std::upper_bound(a.begin(), a.end(), x));
}
template <class T>
void unq_sort(std::vector<T> &a) {
	std::sort(a.begin(), a.end());
	a.erase(std::unique(a.begin(), a.end()), a.end());
}
template <class T>
std::vector<int> press(const std::vector<T> &a) {
	std::vector<T> vec = a;
	unq_sort(vec);
	std::vector<int> ret;
	for(const auto &v : a) ret.push_back(lb(vec, v));
	return ret;
}
#line 1 "SPJ-Library/template/header.hpp"
#include <bits/stdc++.h>
#line 2 "SPJ-Library/template/io.hpp"

#line 4 "SPJ-Library/template/io.hpp"

#line 8 "SPJ-Library/template/debug.hpp"

#line 3 "SPJ-Library/template/constants.hpp"

constexpr int inf = 1000'000'000;
constexpr long long INF = 1'000'000'000'000'000'000LL;
constexpr int mod_1000000007 = 1000000007;
constexpr int mod_998244353 = 998244353;
const long double pi = acosl(-1.);
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
#line 10 "SPJ-Library/template/debug.hpp"

namespace viewer {

template <typename T, typename U>
void view(const std::pair<T, U> &p);

template <class T0, class T1, class T2>
void view(const std::tuple<T0, T1, T2> &p);

template <class T0, class T1, class T2, class T3>
void view(const std::tuple<T0, T1, T2, T3> &p);

void view(const long long &e);

void view(const int &e);

template <typename T>
void view(const T &e);

template <typename T>
void view(const std::set<T> &s);

template <typename T>
void view(const std::unordered_set<T> &s);

template <typename T>
void view(const std::multiset<T> &s);

template <typename T>
void view(const std::unordered_multiset<T> &s);

template <typename T>
void view(const std::vector<T> &v);

template <typename T, std::size_t ary_size>
void view(const std::array<T, ary_size> &v);

template <typename T>
void view(const std::vector<std::vector<T>> &vv);

template <typename T, typename U>
void view(const std::vector<std::pair<T, U>> &v);

template <class T0, class T1, class T2>
void view(const std::vector<std::tuple<T0, T1, T2>> &v);

template <class T0, class T1, class T2, class T3>
void view(const std::vector<std::tuple<T0, T1, T2, T3>> &v);

template <typename map_type>
void view_map_container(const map_type &m);

template <typename T, typename U>
void view(const std::map<T, U> &m);

template <typename T, typename U>
void view(const std::unordered_map<T, U> &m);

template <typename container_type>
void view_container(const container_type &c, bool vertically = false) {
	typename container_type::const_iterator begin = c.begin();
	const typename container_type::const_iterator end = c.end();
	if(vertically) {
		std::cerr << "{\n";
		while(begin != end) {
			std::cerr << '\t';
			view(*(begin++));
			if(begin != end) std::cerr << ',';
			std::cerr << '\n';
		}
		std::cerr << '}';
		return;
	}
	std::cerr << "{ ";
	while(begin != end) {
		view(*(begin++));
		if(begin != end) std::cerr << ',';
		std::cerr << ' ';
	}
	std::cerr << '}';
}

template <typename T, typename U>
void view(const std::pair<T, U> &p) {
	std::cerr << '(';
	view(p.first);
	std::cerr << ", ";
	view(p.second);
	std::cerr << ')';
}

template <class T0, class T1, class T2>
void view(const std::tuple<T0, T1, T2> &p) {
	std::cerr << '(';
	view(std::get<0>(p));
	std::cerr << ", ";
	view(std::get<1>(p));
	std::cerr << ", ";
	view(std::get<2>(p));
	std::cerr << ')';
}

template <class T0, class T1, class T2, class T3>
void view(const std::tuple<T0, T1, T2, T3> &p) {
	std::cerr << '(';
	view(std::get<0>(p));
	std::cerr << ", ";
	view(std::get<1>(p));
	std::cerr << ", ";
	view(std::get<2>(p));
	std::cerr << ", ";
	view(std::get<3>(p));
	std::cerr << ')';
}

void view(const long long &e) {
	if(e == INF)
		std::cerr << "INF";
	else if(e == -INF)
		std::cerr << "-INF";
	else
		std::cerr << e;
}

void view(const int &e) {
	if(e == inf)
		std::cerr << "inf";
	else if(e == -inf)
		std::cerr << "-inf";
	else
		std::cerr << e;
}

template <typename T>
void view(const T &e) {
	std::cerr << e;
}

template <typename T>
void view(const std::set<T> &s) {
	view_container(s);
}

template <typename T>
void view(const std::unordered_set<T> &s) {
	view_container(s);
}

template <typename T>
void view(const std::multiset<T> &s) {
	view_container(s);
}

template <typename T>
void view(const std::unordered_multiset<T> &s) {
	view_container(s);
}

template <typename T>
void view(const std::vector<T> &v) {
	view_container(v);
}

template <typename T, std::size_t ary_size>
void view(const std::array<T, ary_size> &v) {
	view_container(v);
}

template <typename T>
void view(const std::vector<std::vector<T>> &vv) {
	view_container(vv, true);
}

template <typename T, typename U>
void view(const std::vector<std::pair<T, U>> &v) {
	view_container(v, true);
}

template <class T0, class T1, class T2>
void view(const std::vector<std::tuple<T0, T1, T2>> &v) {
	view_container(v, true);
}

template <class T0, class T1, class T2, class T3>
void view(const std::vector<std::tuple<T0, T1, T2, T3>> &v) {
	view_container(v, true);
}

template <typename map_type>
void view_map_container(const map_type &m) {
	std::cerr << "{\n";
	for(typename map_type::const_iterator it = m.begin(); it != m.end(); it++) {
		std::cerr << "\t[";
		view(it->first);
		std::cerr << "] : ";
		view(it->second);
		std::cerr << '\n';
	}
	std::cerr << "}";
}

template <typename T, typename U>
void view(const std::map<T, U> &m) {
	view_map_container(m);
}

template <typename T, typename U>
void view(const std::unordered_map<T, U> &m) {
	view_map_container(m);
}

}  // namespace viewer

// when compiling : g++ foo.cpp -DLOCAL
#ifdef LOCAL
void debug_out() {}
template <typename T>
void debug_out(const T &x) {
	viewer::view(x);
}
template <typename Head, typename... Tail>
void debug_out(const Head &H, const Tail &... T) {
	viewer::view(H);
	std::cerr << ", ";
	debug_out(T...);
}
#define debug(...)                                                \
	do {                                                          \
		std::cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : ["; \
		debug_out(__VA_ARGS__);                                   \
		std::cerr << "]\n";                                       \
	} while(0)
#else
#define debug(...) (void(0))
#endif
#line 2 "SPJ-Library/template/scanner.hpp"

#line 6 "SPJ-Library/template/scanner.hpp"

namespace scanner {
template <class T>
void scan(T &a) {
	std::cin >> a;
}

template <class T, class L>
void scan(std::pair<T, L> &p) {
	scan(p.first);
	scan(p.second);
}

template <class T0, class T1, class T2>
void scan(std::tuple<T0, T1, T2> &p) {
	T0 t0;
	T1 t1;
	T2 t2;
	scan(t0);
	scan(t1);
	scan(t2);
	p = std::make_tuple(t0, t1, t2);
}

template <class T0, class T1, class T2, class T3>
void scan(std::tuple<T0, T1, T2, T3> &p) {
	T0 t0;
	T1 t1;
	T2 t2;
	T3 t3;
	scan(t0);
	scan(t1);
	scan(t2);
	scan(t3);
	p = std::make_tuple(t0, t1, t2, t3);
}

template <class T>
void scan(std::vector<T> &a) {
	for(auto &i : a) scan(i);
}

void INPUT() {}
template <class Head, class... Tail>
void INPUT(Head &head, Tail &... tail) {
	scan(head);
	INPUT(tail...);
}
}  // namespace scanner
#line 7 "SPJ-Library/template/io.hpp"

#define VEC(type, name, size) \
	vector<type> name(size);  \
	scanner::INPUT(name)
#define VVEC(type, name, h, w)                     \
	vector<vector<type>> name(h, vector<type>(w)); \
	scanner::INPUT(name)
#define INT(...)     \
	int __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LL(...)            \
	long long __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define STR(...)        \
	string __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define CHR(...)      \
	char __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define DBL(...)        \
	double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LD(...)              \
	long double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define TPL3(type0, type1, type2, name)   \
	std::tuple<type0, type1, type2> name; \
	scanner::INPUT(name);
#define TPL4(type0, type1, type2, type3, name)   \
	std::tuple<type0, type1, type2, type3> name; \
	scanner::INPUT(name);

template <typename T1, typename T2>
std::istream &operator>>(std::istream &is, std::pair<T1, T2> &p) {
	is >> p.first >> p.second;
	return is;
}

template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &p) {
	os << p.first << ' ' << p.second;
	return os;
}

struct fast_io {
	fast_io() {
		std::ios::sync_with_stdio(false);
		std::cin.tie(nullptr);
		std::cout << std::fixed << std::setprecision(15);
		srand((unsigned)time(NULL));
	}
} fast_io_;
#line 2 "SPJ-Library/template/macros.hpp"

#define foa(s, v) for(auto &s : v)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pcnt(n) __builtin_popcountll((long long)n)

#define REPname(a, b, c, d, e, ...) e
#define rep(...) REPname(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__)
#define REP0(x) for(int Counter_in_rep_macro = 0; Counter_in_rep_macro < (x); ++Counter_in_rep_macro)
#define REP1(i, x) for(int i = 0; i < (x); ++i)
#define REP2(i, l, r) for(int i = (l); i < (r); ++i)
#define REP3(i, l, r, c) for(int i = (l); i < (r); i += (c))
#define DREPname(a, b, c, d, e, ...) e
#define drep(...) DREPname(__VA_ARGS__, DREP3, DREP2, DREP1)(__VA_ARGS__)
#define DREP1(i, x) for(int i = (x)-1; i >= 0; --i)
#define DREP2(i, l, r) for(int i = (r)-1; i >= (l); --i)
#define DREP3(i, l, r, c) for(int i = (r)-1; i >= (l); i -= (c))

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vvvi = std::vector<std::vector<std::vector<int>>>;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
template <class T = ll>
using V = std::vector<T>;
template <class T = ll>
using VV = V<V<T>>;
template <class T = ll>
using VVV = V<V<V<T>>>;
template <class T = ll>
using pqup = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T = ll>
using pqdn = std::priority_queue<T>;
#line 7 "SPJ-Library/template/kuma.hpp"

using namespace std;
#line 6 "a.cpp"
void solve() {}
int main() {
	INT(n, m);
	vector<ll> c(n);
	rep(i, n) cin >> c[i];
	vector<ll> adj(n);
	rep(m) {
		INT(u, v);
		u--;
		v--;
		adj[u] |= 1LL << v;
		adj[v] |= 1LL << u;
	}

	ll ans = INF;
	auto dfs = [&](int now, auto self, ll banned) -> void {
		if(now == n - 1) {
			banned |= adj[now];
			ll cost = 0;
			rep(i, n) {
				if(1LL & (banned >> i)) cost += c[i];
			}
			chmin(ans, cost);
			return;
		}
		rep(nxt, n) {
			ll nxtbit = 1LL << nxt;
			if((adj[now] & nxtbit) && !(banned & nxtbit)) {
				self(nxt, self, banned | adj[now]);
			}
		}
		return;
	};

	dfs(0, dfs, 1LL << 0);
	drop(ans);
}
accuracy: 1
time_ms: 70
memory_kb: 3464
final_rank: 14

code_snippet: #pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
#include<chrono>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 998244353;
//constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;

#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}
template<typename T>
void cinarray(vector<T>& v) {
	rep(i, v.size())cin >> v[i];
}
template<typename T>
void coutarray(vector<T>& v) {
	rep(i, v.size()) {
		if (i > 0)cout << " "; cout << v[i];
	}
	cout << "\n";
}
ll mod_pow(ll x, ll n, ll m = mod) {
	if (n < 0) {
		ll res = mod_pow(x, -n, m);
		return mod_pow(res, m - 2, m);
	}
	if (abs(x) >= m)x %= m;
	if (x < 0)x += m;
	//if (x == 0)return 0;
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
struct modint {
	int n;
	modint() :n(0) { ; }
	modint(ll m) {
		if (m < 0 || mod <= m) {
			m %= mod; if (m < 0)m += mod;
		}
		n = m;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[a - b];
}

ll gcd(ll a, ll b) {
	a = abs(a); b = abs(b);
	if (a < b)swap(a, b);
	while (b) {
		ll r = a % b; a = b; b = r;
	}
	return a;
}
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;
const ld pi = acosl(-1.0);
template<typename T>
void addv(vector<T>& v, int loc, T val) {
	if (loc >= v.size())v.resize(loc + 1, 0);
	v[loc] += val;
}
/*const int mn = 100005;
bool isp[mn];
vector<int> ps;
void init() {
	fill(isp + 2, isp + mn, true);
	for (int i = 2; i < mn; i++) {
		if (!isp[i])continue;
		ps.push_back(i);
		for (int j = 2 * i; j < mn; j += i) {
			isp[j] = false;
		}
	}
}*/

//[,val)
template<typename T>
auto prev_itr(set<T>& st, T val) {
	auto res = st.lower_bound(val);
	if (res == st.begin())return st.end();
	res--; return res;
}

//[val,)
template<typename T>
auto next_itr(set<T>& st, T val) {
	auto res = st.lower_bound(val);
	return res;
}
using mP = pair<modint, modint>;


int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
//-----------------------------------------

ll exi[40];
void solve() {
	int n, m; cin >> n >> m;
	vector<vector<int>> G(n);
	vector<int> c(n);
	rep(i, n)cin >> c[i];
	rep(i, m) {
		int a, b; cin >> a >> b; a--; b--;
		exi[a] |= (1ll << b);
		exi[b] |= (1ll << a);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	rep(i, n)exi[i] |= (1ll << i);
	vector<int> cur = { 0 };
	ll ban = 0;
	int ans = mod;
	function<void()> yaru = [&]() {
		if (cur.back() == n - 1) {
			//hantei
			int cost = 0;
			ll cban = ban;
			ban |= exi[n - 1];
			rep(i, n) {
				if (ban & (1ll << i)) {
					cost += c[i];
				}
			}
			chmin(ans, cost);
			ban = cban;
			return;
		}
		ll cban = ban;
		int las = cur.back();
		ban |= exi[las];
		for (int to : G[las]) {
			if (cban & (1ll << to))continue;
			cur.push_back(to);
			yaru();
			cur.pop_back();
		}
		ban = cban;
	};
	yaru();
	cout << ans << "\n";
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init_f();
	//init();
	//while(true)
	//useexpr();
	//int t; cin >> t; rep(i, t)
	solve();
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 11676
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
void chmin(int& a, int b){ if(a > b) a = b; }

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> c(n);
    for(int& i : c) cin >> i;
    vector g(n, vector<int>{});
    vector<uint64_t> g_bit(n);
    while(m--){
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
        g_bit[a] ^= 1ULL << b;
        g_bit[b] ^= 1ULL << a;
    }
    int ans = INF;
    auto dfs = [&](int at, uint64_t bit, auto dfs){
        const uint64_t bit2 = bit | g_bit[at];
        if(at == n - 1){
            int cnt = 0;
            for(int i = 0; i < n; i++) if(bit2 >> i & 1) cnt += c[i];
            chmin(ans, cnt);
            return;
        }
        for(int i : g[at]) if(~bit >> i & 1) dfs(i, bit2, dfs);
    };
    dfs(0, 0, dfs);
    cout << ans << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 3452
final_rank: 9

code_snippet: #include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <bitset>
#include <stack>
#define Endl endl
#define mp make_pair
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define srand() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l,r) uniform_int_distribution<int>(l,r)(rng)
typedef unsigned long long ull;
const int inf=1039074182;
using namespace std;
int a[45];
vector <int> vec[45];
int n,m;
int best;
bitset <40> connect[45];

inline int getcost(bitset <40> bit)
{
	int res=0;
	for(int i=0;i<40;i++)
	{
		if(bit[i]) res+=a[i];
	}
	return res;
}

void dfs(int x,int cost,bitset<40> now)
{
//	if(cost!=getcost(now)) cout<<x<<' '<<cost<<' '<<now<<endl;
	int newcost=cost+getcost(connect[x] ^ (now & connect[x]));
	if(newcost>=best) return;
	if(x==n-1)
	{
		best=newcost;
		return;
	}
	bitset <40> t;
	for(int i=0;i<vec[x].size();i++)
	{
		if(now[vec[x][i]]) continue;
		dfs(vec[x][i],newcost,now | connect[x]);
	}
}

int main()
{
//	freopen("input.txt","r",stdin);
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		connect[i][i]=true;
	}
	int x,y;
	for(int i=0;i<m;i++)
	{
		cin>>x>>y;
		x--;
		y--;
		vec[x].push_back(y);
		vec[y].push_back(x);
		connect[x][y]=true;
		connect[y][x]=true;
	}
	int cost=0;
	for(int i=0;i<n;i++)
	{
		if(connect[0][i]) cost+=a[i];
	}
	best=inf;
	dfs(0,0,0);
	cout<<best<<endl;
	return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 3160
final_rank: 12

code_snippet: #include <bits/stdc++.h>

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
// const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

int main() {
  int N, M;
  cin >> N >> M;
  vector< int > C(N);
  cin >> C;
  UnWeightedGraph g(N);
  auto uku = make_v< int64 >(N);
  for(int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    g[x].emplace_back(y);
    g[y].emplace_back(x);
    uku[x] |= 1LL << y;
    uku[y] |= 1LL << x;
  }
  vector< int > t(N, -1);
  auto rec = MFP([&](auto rec, int idx, int time) -> int {
    if(idx + 1 == N) {
      int cost = 0;
      int64 bit = 0;
      for(int i = 0; i < N; i++) {
        if(~t[i]) bit |= uku[i];
      }
      for(int i = 0; i < N; i++) {
        if((bit >> i) & 1) cost += C[i];
      }
      return cost;
    }
    int ret = inf;
    for(auto &to : g[idx]) {
      if(~t[to]) continue;

      bool f = false;
      for(int i = 0; i < N; i++) {
        if(i == idx) continue;
        if(~t[i] && (uku[i] >> to) & 1) f = true;
      }
      if(f) continue;

      t[to] = time + 1;
      chmin(ret, rec(to, time + 1));
      t[to] = -1;
    }
    return ret;
  });
  t[0] = 0;
  cout << rec(0, 0) << endl;
}
accuracy: 1
time_ms: 380
memory_kb: 3224
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;

const int maxn = 40;
uint64_t adj[maxn];
int n, m, c[maxn], sum[2][1 << 20];

int Eval(uint64_t mask) {
    return sum[0][mask & ((1LL << (n / 2)) - 1)] + sum[1][mask >> (n / 2)];
}

int dfs(int x, uint64_t ng, uint64_t f) {
    if (x == n - 1) return Eval(ng);
    uint64_t cand = (adj[x] & ~f);
    int res = 1E9;
    while (cand > 0) {
        int u = __builtin_ctzll(cand & -cand);
        if (u != x)
            res = min(res, dfs(u, ng | adj[x] | adj[u], (adj[x] ^ (1ULL << u)) | f));
        cand -= (1ULL << u);
    }
    return res;
}

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++i) scanf("%d", &c[i]);
    for (int i = 0; i < n; ++i) adj[i] |= (1ULL << i);
    for (int i = 0; i < m; ++i) {
        int u, v; scanf("%d%d", &u, &v);
        --u, --v;
        adj[u] |= (1ULL << v);
        adj[v] |= (1ULL << u);
    }
    for (int i = 0; i < (1 << (n / 2)); ++i) {
        for (int j = 0; j < n / 2; ++j) {
            if (i >> j & 1)
                sum[0][i] += c[j];
        }
    }
    for (int i = 0; i < (1 << (n - n / 2)); ++i) {
        for (int j = 0; j < n - n / 2; ++j) {
            if (i >> j & 1)
                sum[1][i] += c[j + n / 2];
        }
    }
    printf("%d\n", dfs(0, 0LL, 0LL));
}
accuracy: 1
time_ms: 90
memory_kb: 11404
final_rank: 17

code_snippet: #include <bits/stdc++.h>
#define int long long
#define INF 1000000007
using namespace std;

int n,m,a[50],ans=INF;
vector<int> v[50];

inline void dfs(int loc,int mask1,int cost)
{
	int mask2=mask1;
	if(!((mask1>>loc)&1ll)){
		cost+=a[loc];
		mask1|=(1ll<<(loc));
	}
	for(int i=0;i<v[loc].size();i++){
		if(!(mask1&(1ll<<(v[loc][i])))){
			cost+=a[v[loc][i]];
			mask1|=(1ll<<(v[loc][i]));
		}
	}
	if(cost>=ans) return;
	if(loc==n-1){
		ans=cost;
		return;
	}
	for(int i=0;i<v[loc].size();i++){
		if(!(mask2&(1ll<<(v[loc][i])))){
			dfs(v[loc][i],mask1,cost);
		}
	}
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		x--;y--;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	dfs(0,0,0);
	cout<<ans<<endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3208
final_rank: 2

code_snippet: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;++i)
#define REP(i,n) for (int i=1;i<=n;++i)
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define read(x) scanf("%d",&x)
int n,m;
int c[45];
vector<int> E[45];
int ans=1e9;
inline void dfs(int v,ll seen,int cost){
	ll nseen=seen;int ncost=cost;
	if (!(nseen&(1ll<<v))){
		nseen|=1ll<<v;
		ncost+=c[v];
	}
	for (int i=0;i<E[v].size();++i){
		int u=E[v][i];
		if (!(nseen&(1ll<<u))){
			ncost+=c[u];
			nseen|=1ll<<u;
		}
	}
	if (ncost>=ans) return;
	if (v==n){
		ans=ncost;return;
	}
	for (int i=0;i<E[v].size();++i){
		int u=E[v][i];
		if (!(seen&(1ll<<u))) dfs(u,nseen,ncost);
	}
	
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for (int i=1;i<=n;++i) cin>>c[i];
	for (int i=1;i<=m;++i){
		int x,y;
		cin>>x>>y;
		E[x].pb(y);E[y].pb(x);
	}
	dfs(1,0,0);
	cout<<ans<<endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3236
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long
#define vi vector <int>
#define pii pair <int, int>
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i,n) for (int i = 0; i < (int) (n); ++ i)
#define foreach(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); ++ it)

inline int read() {
	int x = 0, f = 1, c = getchar();
	for (;!isdigit(c);c = getchar()) if (c == '-') f ^= 1;
	for (; isdigit(c);c = getchar()) x = x * 10 + c - '0';
	return f ? x : -x;
}

int n, m;
vi g[45];
ll msk[45];
map <ll, int> dis[45];
int d[45];
typedef pair <int, pair <int, ll> > T;
priority_queue <T, vector <T>, greater <T> > pq;

int main() {
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
	n = read(), m = read();
	rep(i, n) d[i] = read();
	rep(i, m) {
		int u = read() - 1, v = read() - 1;
		g[u].pb(v); g[v].pb(u);
	}
	rep(i, n) {
		msk[i] |= 1LL << i;
		rep(j, g[i].size()) {
			msk[i] |= 1LL << g[i][j];
		}
	}
	int a = 0;
	rep(i, n) if (msk[0] & 1LL << i) a += d[i];
	dis[0][msk[0]] = a;
	pq.push(mp(a, mp(0, msk[0])));
	while (!pq.empty()) {
		int dd = pq.top().first, u = pq.top().second.first;
		ll mskk = pq.top().second.second;
		pq.pop();
		if (dd != dis[u][mskk]) continue;
//		printf("%d %d %lld\n", dd, u, mskk);
		if (u == n - 1) return printf("%d\n", dd) & 0;
		rep(i, g[u].size()) {
			int v = g[u][i];
			ll nmsk = mskk | msk[v];
			int cst = 0;
			rep(j, n) if (nmsk & 1LL << j) cst += d[j];
			if (!dis[v].count(nmsk) || dis[v][nmsk] > cst) {
				dis[v][nmsk] = cst;
//				printf("to %d %lld\n", v, nmsk);
				pq.push(mp(cst, mp(v, nmsk)));
			}
		}
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4388
final_rank: 8

code_snippet: #include <bits/stdc++.h>

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fr, to)    for (int i = fr; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 40, inf = 0x3f3f3f3f;
int n, m, s = 1, e, cnt[nsz + 5], w[nsz + 5], ans = inf;
vector<int> g[nsz + 5];

void dfs(int u = s, int p = s, int res = w[s]) {
    ++cnt[u];
    for (int v : g[u]) {
        if (!cnt[v]) {
            res += w[v];
        }
        ++cnt[v];
    }
    if (u == e) {
        ans = min(ans, res);
    } else {
        for (int v : g[u]) {
            if (cnt[v] > 1)  continue;
            dfs(v, u, res);
        }
    }
    --cnt[u];
    for (int v : g[u]) {
        --cnt[v];
        if (!cnt[v]) {
            res -= w[v];
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    e = n;
    cont (u, n) {
        cin >> w[u];
    }
    cont (i, m) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs();
    cout << ans << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3236
final_rank: 4

code_snippet: /*


*/
#include <cstdio>
#include <cctype>
#include <algorithm>
#define gc() getchar()
typedef long long LL;
const int N=4500,M=100000;

int n,Ans,Enum,H[N],nxt[M],to[M],A[N],ban[N];

inline int read()
{
	int now=0;register char c=gc();
	for(;!isdigit(c);c=gc());
	for(;isdigit(c);now=now*10+c-48,c=gc());
	return now;
}
inline void AE(int u,int v)
{
	to[++Enum]=v, nxt[Enum]=H[u], H[u]=Enum;
	to[++Enum]=u, nxt[Enum]=H[v], H[v]=Enum;
}
void DFS(int x,int cost)
{
	if(x==n)
	{
		for(int i=H[x]; i; i=nxt[i]) !ban[to[i]]&&(cost+=A[to[i]]);
		Ans=std::min(Ans,cost);
		return;
	}
	for(int i=H[x]; i; i=nxt[i]) !ban[to[i]]&&(cost+=A[to[i]]), ++ban[to[i]];
	for(int i=H[x]; i; i=nxt[i]) if(ban[to[i]]==1) DFS(to[i],cost);
	for(int i=H[x]; i; i=nxt[i]) --ban[to[i]];
}

int main()
{
	int n=read(),m=read();
	for(int i=1; i<=n; ++i) A[i]=read();
	for(int i=1; i<=m; ++i) AE(read(),read());
	::n=n, Ans=2e9, ban[1]=1, DFS(1,A[1]), printf("%d\n",Ans);

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 2728
final_rank: 1

code_snippet: #include<bits/stdc++.h>
#define N 110000
#define L 100000
#define eps 1e-7
#define inf 1e9+7
#define db double
#define ll long long
#define ldb long double
using namespace std;
inline int read()
{
    char ch=0;
    int x=0,flag=1;
    while(!isdigit(ch)){ch=getchar();if(ch=='-')flag=-1;}
    while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return x*flag;
}
struct edge{int to,nxt;}e[N*2];
int num,head[N];
inline void add(int x,int y){e[++num]={y,head[x]};head[x]=num;}
int n,m,ans=inf,w[N],vis[N];
void dfs(int x,int s)
{
    if(++vis[x]==1)s+=w[x];
    for(int i=head[x];i!=-1;i=e[i].nxt){int to=e[i].to;if(++vis[to]==1)s+=w[to];}
    if(x==n)
    {
        ans=min(ans,s);
        vis[x]--;for(int i=head[x];i!=-1;i=e[i].nxt)vis[e[i].to]--;return;
        
    }
    for(int i=head[x];i!=-1;i=e[i].nxt){int to=e[i].to;if(vis[to]==1)dfs(to,s);}
    vis[x]--;for(int i=head[x];i!=-1;i=e[i].nxt)vis[e[i].to]--;
}
int main()
{
    n=read();m=read();
    for(int i=1;i<=n;i++)w[i]=read();
    num=-1;memset(head,-1,sizeof(head));
    for(int i=1;i<=m;i++)
    {
        int x=read(),y=read();
        add(x,y);add(y,x);
    }
    dfs(1,0);printf("%d\n",ans);
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3664
final_rank: 11

code_snippet: #include<cstdio>
#include<cstring>
#include<ctime>
#include<algorithm>
#include<vector>

class Solution{
private :
    typedef std::vector<int>::iterator it;
    static const int maxn = 50;

    int n, m, a[maxn], ans;
    bool vis[maxn], used[maxn];
    std::vector<int> e[maxn];

    int Make() {
        memset(used, 0, sizeof(used));
        for (register int i = 1; i <= n; i++) {
            if (!vis[i]) {
                continue;
            }
            for (register it j = e[i].begin(); j != e[i].end(); j++) {
                used[*j] = 1;
            }
        }
        int res = 0;
        for (register int i = 1; i <= n; i++) {
            if (used[i]) {
                res += a[i];
            }
        }
        return res;
    }

    void DFS(int now) {
        if (now == n) {
            ans = std::min(ans, Make());
            vis[now] = 0;
            return;
        }
        if (vis[now]) {
            return;
        }
        vis[now] = 1;
        
        int v = e[now][rand() % e[now].size()];
        DFS(v);
        
        vis[now] = 0;
    }
    
public :
    Solution() {
        Get();
        Solve();
    }

    void Get() {
        scanf("%d %d", &n, &m);
        for (register int i = 1; i <= n; i++) {
            scanf("%d", a + i);
            ans += a[i];
        }
        for (register int i = 1, u, v; i <= m; i++) {
            scanf("%d %d", &u, &v);
            e[u].push_back(v);
            e[v].push_back(u);
        }
    }

    void Solve() {
        srand((unsigned)time(0));
        for (register int i = 1; i <= 1000000; i++) {
            DFS(1);
        }
        printf("%d\n", ans);
    }
};
Solution sol;

int main() {}
accuracy: 0.017241379310344827
time_ms: 60
memory_kb: 2724
final_rank: 20

code_snippet: #include <bits/stdc++.h>

using namespace std;

int n, m;
vector<int> c, visited;
vector<vector<int>> adj;

int Dfs(int cur) {
    if (cur == n - 1) {
        int res = 0;
        for (int dst : adj[cur]) if (visited[dst] == -1) res += c[dst];
        return res;
    }

    int res = 0;
    for (int dst : adj[cur]) {
        if (visited[dst] == -1) {
            visited[dst] = cur;
            res += c[dst];
        }
    }

    int d = INT_MAX;
    for (int dst : adj[cur])
        if (visited[dst] == cur) d = min(d, Dfs(dst));

    for (int dst : adj[cur])
        if (visited[dst] == cur) visited[dst] = -1;

    return (INT_MAX <= d ? d : res + d);
}

int main() {
    cin.tie(0); ios::sync_with_stdio(false);

    cin >> n >> m;
    c.resize(n); visited.resize(n, -1); adj.resize(n);
    for (int v = 0; v < n; ++v) cin >> c[v];
    for (int i = 0, u, v; i < m; ++i) {
        cin >> u >> v;
        adj[u - 1].push_back(v - 1);
        adj[v - 1].push_back(u - 1);
    }

    visited[0] = -2;
    cout << Dfs(0) + c[0] << endl;

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3216
final_rank: 3

code_snippet: #include<bits/stdc++.h>
#define ll long long
#define P pair < int , ll >
#define PP pair < int , P >
#define st first
#define nd second
//This code is written by Itst
using namespace std;

inline int read(){
	int a = 0;
	char c = getchar();
	bool f = 0;
	while(!isdigit(c) && c != EOF){
		if(c == '-')
			f = 1;
		c = getchar();
	}
	if(c == EOF)
		exit(0);
	while(isdigit(c)){
		a = (a << 3) + (a << 1) + (c ^ '0');
		c = getchar();
	}
	return f ? -a : a;
}

map < P , int > dp;
int N , M , ans , head[45] , val[45] , cntEd;
struct Edge{
	int end , upEd;
}Ed[2010];
ll fj[45];

inline void addEd(int a , int b){
	Ed[++cntEd].end = b;
	Ed[cntEd].upEd = head[a];
	head[a] = cntEd;
	fj[a] |= 1ll << b;
}

void Dijk(){
    priority_queue < PP > q;
	int all = 0;
	for(int i = 0 ; i < N ; ++i)
		if(fj[0] & (1 << i))
			all += val[i];
	dp.clear();
	dp[P(0 , fj[0])] = all;
	q.push(PP(-all , P(0 , fj[0])));
	while(!q.empty()){
		PP t = q.top();
		q.pop();
		if(-t.st > dp[t.nd])
			continue;
		int x = t.nd.st , cost = dp[t.nd];
		ll y = t.nd.nd;
		if(x == N - 1){
			ans = cost;
			return;
		}
		for(int i = head[x] ; i ; i = Ed[i].upEd){
			ll k = y | fj[Ed[i].end];
			int c = 0;
			for(int j = 0 ; j < N ; ++j)
				if(k & (1ll << j))
					c += val[j];
			if(!dp.count(P(Ed[i].end , k)) || dp[P(Ed[i].end , k)] > c){
				dp[P(Ed[i].end , k)] = c;
				q.push(PP(-c , P(Ed[i].end , k)));
			}
		}
	}
}

int main(){
	while(1){
		N = read();
		M = read();
		ans = 1e9;
		for(int i = 0 ; i < N ; ++i)
			val[i] = read();
		cntEd = 0;
		memset(head , 0 , sizeof(head));
		for(int i = 0 ; i < N ; ++i)
			fj[i] = 1ll << i;
		for(int i = 1 ; i <= M ; ++i){
			int a = read() - 1 , b = read() - 1;
			addEd(a , b);
			addEd(b , a);
		}
		Dijk();
		printf("%d\n" , ans);
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4568
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define N 41
typedef long long ll;
const int inf=0x3f3f3f3f;
ll adj[N];
int a[N],que[N];
vector<int> g[N];
int n,m,ans,cnt=0,kk=0;
unordered_set<ll> se;
bool bfs(int beg,ll s)
{
    int l=0,r=0,x,y;
    que[0]=beg;
    while(l<=r)
    {
        x=que[l++];
        if(x==n-1) return true;
        for(int y:g[x])
        {
            if((s>>y)&1) continue;
            s|=1LL<<y;que[++r]=y;
        }
    }
    return false;
}
int calc(int x,ll s1,ll s2)
{
    if(!bfs(x,s1)) return inf;
    s2|=adj[n-1];
    int tot=0;
    for(int i=0;i<n;++i)
        if((s2>>i)&1) tot+=a[i];
    return tot;
}
void dfs(int x,ll s1,ll s2)
{
    if(cnt>=2000000) return;
    ++cnt;
    if(x==n-1)
    {
        // printf("%d %d ?\n",x,calc(x,s1,s2));
        ans=min(ans,calc(x,s1,s2));
        return;
    }
    ll h=s1*100+x;
    if(se.count(h)) return;
    se.insert(h);
    // printf("%d %d %d !!\n",x,calc(x,s1,s2),ans);
    if(calc(x,s1,s2)>=ans) return;
    
    for(int y:g[x])
    {
        if((s1>>y)&1) continue;
        dfs(y,s1|(1LL<<y),s2|adj[y]);
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;++i) 
    {
        scanf("%d",&a[i]);
        adj[i]=1LL<<i;
    }
    int x,y;
    for(int i=1;i<=m;++i)
    {
        scanf("%d%d",&x,&y);
        --x;--y;
        g[x].push_back(y);g[y].push_back(x);
        adj[x]|=1LL<<y;adj[y]|=1LL<<x;
    }
    for(int i=0;i<n;++i) 
        shuffle(g[i].begin(),g[i].end(),default_random_engine(0));
    ans=inf;
    dfs(0,1,adj[0]);
    printf("%d\n",ans);
    return 0;
}
accuracy: 0.6724137931034483
time_ms: 590
memory_kb: 60816
final_rank: 19