为啥都是33554422

P4779 【模板】单源最短路径(标准版)

Chtholly_is_cute @ 2024-03-22 20:10:25

#include<bits/stdc++.h>
using namespace std;
struct edge{
    int v,w,nex;
}e[int(520131.4)];
int head[int(131452.0)],tot=0;
void add(int u,int v,int w){
    e[++tot].v=v;
    e[tot].w=w;
    e[tot].nex=head[u];
    head[u]=tot;
}
int n,m,s;
int dis[100010];
struct node
{
    int u,d;
    bool operator<(const node &x)const{
        return d>x.d;
    }
};
void ma(){
    int i;
    for(int i=1;i<=n;i++)dis[i]=(1ll<<25);
    dis[s]=0;
    priority_queue<node>Q;
    Q.push((node){s,0});
    while(!Q.empty()){
        node f=Q.top();
        Q.pop();
        int u=f.u,d=f.d;
        if(d!=dis[u])continue;
        for(i=head[u];i;i=e[i].nex);
        {
            int v=e[i].v,w=e[i].w;
            if(dis[u]+w<dis[v]){
                dis[v]=dis[u]+w;
                Q.push((node){v,dis[v]});
            }
        }
    }
}
int main(){
    cin>>n>>m>>s;
    int x,y,z;
    for(int i=1;i<=m;i++){
        cin>>x>>y>>z;
        add(x,y,z);
    }
    ma();
    for(int i=1;i<=n;i++){
        cout<<dis[i]<<' ';
    }
}

by kevinZ99 @ 2024-03-22 20:20:46

@andyzhu444

for(i=head[u];i;i=e[i].nex);

what is this

请您把分号去掉


by Chtholly_is_cute @ 2024-03-22 20:23:15

@kevinZ99 因为一个分号而遗臭万年(


by Chtholly_is_cute @ 2024-03-22 20:24:21

@kevinZ99 0分


by kevinZ99 @ 2024-03-22 20:38:14

@andyzhu444 不是68嘛


by kevinZ99 @ 2024-03-22 20:39:38

@andyzhu444 没开long long 然后把(1ll<<32)改成(1ll<<50)就差不多了


|