不对啊,你一个 struct 怎么优先?#include <bits/stdc++.h>
using namespace std;
struct Info {
int x;
bool y;
};
priority_queue<Info> q;
int n, m, k, u, v, s[200001], step[200001][2];
bool in_s[200001];
bool a;
vector<Info> edges[200001];
void bfs() {
memset(step, 255, sizeof(step));
q.push({1, 0});
step[1][0] = 0;
while (!q.empty()) {
Info f = q.top();
q.pop();
if (f.x == n) {
if (step[f.x][0] == -1) printf("%d", step[f.x][1]);
else if (step[f.x][1] == -1) printf("%d", step[f.x][0]);
else printf("%d", min(step[f.x][0], step[f.y][1]));
return;
}
for (Info i : edges[f.x]) {
//printf("(%d, %d), ", i.x, i.y);
if (((f.y == 1 && i.y == 0) || (f.y == 0 && i.y == 1)) && step[i.x][0] == -1) {
step[i.x][0] = step[f.x][f.y] + 1;
q.push({i.x, 0});
//printf("(OK)");
} else if (in_s[f.x] && step[i.x][1] == -1) {
step[i.x][1] = step[f.x][f.y] + 1;
q.push({i.x, 1});
//printf("(ZOK");
}
}
//puts("");
}
printf("-1");
}
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 1; i <= m; ++i) {
scanf("%d%d%d", &u, &v, &a);
edges[u].push_back({v, a});
edges[v].push_back({u, a});
}
for (int i = 1; i <= k; ++i) {
scanf("%d", &s[i]);
in_s[s[i]] = 1;
}
bfs();
return 0;
}
|