___njr___ @ 2022-10-31 21:49:57
#include<bits/stdc++.h>
using namespace std;
#ifdef min
#undef min
#endif
#ifdef max
#undef max
#endif
#ifdef abs
#undef abs
#endif
#ifdef isdigit
#undef isdigit
#endif
#ifdef isalpha
#undef isalpha
#endif
#ifdef MAXN
#undef MAXN
#endif
#define min(a,b) ( a < b ? a : b )
#define max(a,b) ( a > b ? a : b )
#define abs(a) ( a < 0 ? ~a - 1 : a )
#define isdigit(ch) ( ch >= 48 && ch <= 57 )
#define isalpha(ch) ( ( ch >= 97 && ch <= 122 ) || ( ch >= 65 && ch <= 90 ) )
#define MAXN 100010
int i, j, VS, Spot,
Dont_move_spot,
x, y, z;
int * X = &x,
* Y = &y,
* Z = &z;
vector < int > Edge [ MAXN ] ;
vector < int > Base [ MAXN ] ;
bitset < MAXN > Gd;
int dis [ MAXN ] ;
inline int Min_of(int* a, int n)
{
register int Min = a[1];
register int idx = 1;
for (i = 2; i <= n; ++i) if (a[i] < Min) Min = a[i], idx = i;
return idx;
}
inline void Dijstra(int n, int q)
{
dis[q] = 0;
for (i = 0; i < n; ++i) {
Dont_move_spot = Min_of(dis, n);
VS = Edge[Dont_move_spot].size();
for (j = 0; j < VS; ++j) {
Spot = Edge[i][j];
if (Gd[Spot])
continue;
if (dis[Spot] >= dis[i] + Base[i][j])
dis[Spot] = dis[i] + Base[i][j];
}
Gd[Dont_move_spot] = true;
}
}
int q, n, m;
int main(void)
{
scanf("%d%d%d", &n, &m, &q);
for ( i = 0 ; i <= n ; ++i ) Gd [ i ] = false ;
for (i = 0; i < q; ++i) scanf("%d%d%d", X, Y, Z), Edge[x].push_back(y), Edge[y].push_back(x), Base[z].push_back(y), Base[z].push_back(x);
Dijstra(n, q);
for (i = 0; i < n; ++i) printf("%d ", dis[i]);
return 0;
}
#undef min
#undef max
#undef abs
#undef isdigit
#undef isalpha
by masonpop @ 2022-11-13 18:22:13
@liuhaodong2021 您