1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include <queue> #include <tuple> #include <cstdio> #include <vector> #include <utility> #include <cstring>
using namespace std;
unsigned long long dist[10005][15]; bool vis[10005][15]; vector<pair<int, unsigned long long>> web[15];
int main() { memset(dist, 0x3f, sizeof dist); int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= m; i++) { int u, v; unsigned long long w; scanf("%d%d%llu", &u, &v, &w); web[u].push_back({ v, w }); web[v].push_back({ u, w }); } queue<tuple<int, int, unsigned long long>> q; q.push({ 1, 1, 0 }); dist[1][1] = 0; unsigned long long maxn = 0xffffffffffffffff; while (!q.empty()) { tuple<int, int, unsigned long long> uk = q.front(); q.pop(); pair<int, int> u = { get<0>(uk), get<1>(uk) }; unsigned long long w = get<2>(uk); if (u.second == n && w < maxn) maxn = w; for (pair<int, unsigned long long> vk : web[u.second]) { if (u.first & (1 << (vk.first - 1))) continue; tuple<int, int, unsigned long long> v = { u.first | (1 << (vk.first - 1)), vk.first, w ^ vk.second }; q.push(v); } } printf("%llu\n", maxn); return 0; }
|