#A7. SPFA算法-填空
SPFA算法-填空
int n, m;vector<pair<int, int>> a[100005];queue<pair<int, int>> q;int d[100005];bool v[100005]; // 无需填空注释int cnt[100005];bool spfa() {memset(d, 0x3f, sizeof(d));d[1] = {{ input(1) }}; // 填空1:起点初始化v[1] = {{ input(2) }}; // 填空2:标记起点状态q.push({{ input(3) }}); // 填空3:初始入队while (!q.empty()) {int u = q.front().first;q.pop();v[u] = 0;for (int i = 0; i < a[u].size(); i++) {int to = a[u][i].{{ input(4) }}; // 填空4:邻接节点int w = a[u][i].{{ input(5) }}; // 填空5:边权值if ({{ input(6) }}) { // 填空6:松弛条件d[to] = {{ input(7) }}; // 填空7:更新距离cnt[to] = cnt[u] + 1;if ({{ input(8) }}) // 填空8:负环判断return true;if (!v[to]) {v[to] = 1;q.push({{ input(9) }}); // 填空9:入队操作}}}}return {{ input(10) }}; // 填空10:最终返回}