#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 10005;
int n, m, s;
int g[N][N], dist[N];
int p[N];
bool flag[N];
inline int read() {
int x = 0;
char c = getchar();
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return x;
}
void dijkstra(int u) {
for (int i = 1; i <= n; i++) {
if (u != i) {
dist[i] = g[u][i];
flag[i] = false;
}
else {
dist[i] = 0;
flag[i] = true;
}
if (dist[i] == INF) {
p[i] = -1;
}
else {
p[i] = u;
}
}
for (int i = 1; i < n; i++) {
int temp = INF, t = u;
for (int j = 1; j <= n; j++) {
if (!flag[j] && dist[j] < temp) {
temp = dist[j];
t = j;
}
}
if (t == u) {
return;
}
flag[t] = true;
for (int j = 1; j <= n; j++) {
if (!flag[j] && dist[j] > dist[t] + g[t][j]) {
dist[j] = dist[t] + g[t][j];
p[j] = t;
}
}
}
}
int main() {
memset(g, INF, sizeof(g));
memset(dist, INF, sizeof(dist));
n = read();
m = read();
s = read();
for (int i = 1; i <= m; i++) {
int dian1, dian2, quan;
dian1 = read();
dian2 = read();
quan = read();
g[dian1][dian2] = min(g[dian1][dian2], quan);
g[i][i] = 0;
}
dijkstra(s);
for (int i = 1; i <= n; i++) {
int l = dist[i];
if (l == INF) cout << 2147483647 << " ";
else cout << l << " ";
}
return 0;
}
请问为什么错了呀?