rt,代码在本地和IDE都能过样例,结果交了之后全WA。
随后下载了 #1 的数据,在本地与IDE均过,而提交后仍WA( #1数据见帖末 )
蒟蒻代码:(码风差,请见谅)
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
typedef long long ll;
const ll N = 1000000001;
int n, m, s, u, v, w, ma[2];
struct node{
vector<int> to;
vector<ll> vl;
long long dis;
bool u;
} g[10001];
int main(){
scanf("%d%d%d", &n,&m,&s);
while(m--){
scanf("%d%d%lld", &u,&v,&w);
g[u].to.push_back(v);
g[u].vl.push_back(w);
}
for(int i=1; i<=n; ++i)
if(i!=s) g[i].dis = N;
for(int i=0; i<n; ++i){
ma[1] = N;
for(int j=1; j<=n; ++j)
if(g[j].dis<=ma[1] && !g[j].u)
ma[0] = j, ma[1] = g[j].dis;
g[ma[0]].u = 1;
for(int j=0; j<g[ma[0]].to.size(); ++j){
int k = g[ma[0]].dis+g[ma[0]].vl[j];
if(k<g[g[ma[0]].to[j]].dis)
g[g[ma[0]].to[j]].dis = k;
}
}
for(int i=1; i<=n; ++i)
printf("%lld ",g[i].dis);
return 0;
}
#1数据:
输入:
5 15 5
2 5 181
1 5 98
4 2 49
3 2 262
4 3 26
2 4 192
5 1 221
2 2 254
4 4 233
1 5 44
5 4 67
4 2 214
1 1 47
1 1 118
5 4 3
输出:
221 52 29 3 0
感谢大佬相助