void Solve() { priority_queue < TPair, vector <TPair>, greater <TPair> > Q; for (int v = 1; v <= f[n]; v++) d[v] = MAXD; memset(avail, true, sizeof(avail)); d[1] = 0; Q.push(make_pair(d[1], 1)); while (Q.size()) { TPair u = Q.top(); Q.pop(); if (!avail[u.second]) continue; if (u.second == finish) break; avail[u.second] = false; vector <int> u_a = Unencrypt(u.second); for (int i = 0; i < n - 1; i++) for (int j = i + 1; j < n; j++) { vector <int> v_a(u_a); swap(v_a[i], v_a[j]); int v_id = Encrypt(v_a); if (avail[v_id] && d[v_id] > u.first + c[i][j]) { d[v_id] = u.first + c[i][j]; Q.push(make_pair(d[v_id], v_id)); } } } }
void bfs(int s) { int i, j, node; memset(visit, 0, sizeof(visit)); myStack.push(s); while(!myStack.empty()){ node = myStack.top(); myStack.pop(); if(visit[node]) continue; visit[node] = 1; cout << node << " "; REP(i,V) if(G[node][i]) myStack.push(i); } }
worklist_item next_worklist_item() { worklist_item foo = worklist.top(); worklist.pop(); return foo; }