#12095. 珅泽教育CSP-J第一轮模拟考第二十一套 第 30 题
珅泽教育CSP-J第一轮模拟考第二十一套 第 30 题
二、阅读程序(判断题正确填 T,错误填 F;除特殊说明外,判断题 1.5 分,选择题 3 分,共计 40 分)
程序(3)
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int MAXN = 200001;
int main() {
int n, m, l, r, w;
cin >> n >> m;
vector<int> dist(MAXN, -1);
vector<bool> vis(MAXN, false);
vector<vector<pair<int, int>>> go(MAXN);
for (int i = 1; i <= m; i++) {
cin >> l >> r >> w;
go[l].push_back(make_pair(r + 1, w));
go[r + 1].push_back(make_pair(l, -w));
}
queue<int> q;
dist[1] = 0, vis[1] = true;
q.push(1);
while (!q.empty()) {
int x = q.front(); q.pop();
for (auto i : go[x]) {
if (!vis[i.first]) {
vis[i.first] = true;
dist[i.first] = dist[x] + i.second;
q.push(i.first);
}
}
}
if (dist[n + 1] == -1) cout << "sorry" << endl;
else cout << dist[n + 1] << endl;
return 0;
}
假设输入的 是不超过 200000 的正整数,程序每次输入的 保证 。
在程序第 17 行至第 29 行,相同的数可能重复进入队列。( )
{{ select(1) }}
- 正确
- 错误