#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAX_V = 100 + 1;
int V, m;
typedef pair<int, int> P;
struct edge {
int to, cost;
edge(int t, int c) {
to = t;
cost = c;
}
};
vector<edge> map[MAX_V];
int d[MAX_V], book[MAX_V], numv[MAX_V];
void Bellmanford(int st) {
queue<int> q;
fill(d, d + V + 1, INF);
memset(book, 0, sizeof(book));
memset(numv, 0, sizeof(numv));
d[st] = 0, book[st] = 1, numv[st]++;
q.push(st);
while (q.size()) {
int tmp = q.front();
q.pop();
book[tmp] = 0;
for (auto i : map[tmp]) {
if (d[i.to] > d[tmp] + i.cost) {
d[i.to] = d[tmp] + i.cost;
if (!book[i.to]) {
book[i.to] = 1;
numv[i.to]++;
if (numv[i.to] >= V)
d[i.to] = -INF;
if (numv[i.to] <= V)
q.push(i.to);
}
}
}
}
}
int main() {
cin >> V >> m;
while (m--) {
int a, b, c;
cin >> a >> b >> c;
map[a].push_back(edge(b, c));
map[b].push_back(edge(a, c));
}
int ans[V + 1];
memset(ans, 0, sizeof(ans));
for (int i = 1; i <= V; i++) {
Bellmanford(i);
for (int j = 1; j <= V; j++) {
if (d[j] != -INF)
ans[i] = 1;
}
}
for (int i = 1; i <= V; i++)
if (!ans[i])
cout << i << " ";
return 0;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)