tj
2025-07-27 19:53:39
发布于:浙江
3阅读
0回复
0点赞
#include <iostream>
#include <vector>
#include <climits>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
const int INF = INT_MAX;
vector<vector<int>> matrix(n + 1, vector<int>(n + 1, INF));
for (int i = 0; i < m; ++i) {
int city1, city2, cost;
cin >> city1 >> city2 >> cost;
if (cost < matrix[city1][city2]) {
matrix[city1][city2] = cost;
matrix[city2][city1] = cost;
}
}
int targetCity;
cin >> targetCity;
int count = 0;
int totalCost = 0;
for (int j = 1; j <= n; ++j) {
if (j == targetCity) continue;
if (matrix[targetCity][j] != INF) {
count++;
totalCost += matrix[targetCity][j];
}
}
cout << count << " " << totalCost << endl;
return 0;
}
这里空空如也
有帮助,赞一个