标准版ac的代码,弱化版反而爆0,why???
查看原帖
标准版ac的代码,弱化版反而爆0,why???
882793
666wula666楼主2023/7/16 22:53
#include<bits/stdc++.h>
using namespace std;
const int N=1000010;
int n,m;
typedef pair<int, int> PII;
int h[N], e[N], ne[N], idx,w[N];
int dist[N];
bool st[N];
  priority_queue<PII,vector<PII>,greater<PII>>heap;
void add(int a, int b, int c)  // 添加一条边a->b,边权为c
{
    e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx ++ ;
}


void dijkstra(){
    memset(dist,2147483647,sizeof dist);
   dist[1]=0;
 
   heap.push({0,1});
   while(heap.size()){
       auto t=heap.top();
       heap.pop();
       int ver=t.second,distance=t.first;
       if(st[ver])continue;
       st[ver]=true;
       for(int i=h[ver];i!=-1;i=ne[i]){
           int j=e[i];
           if(dist[j]>distance+w[i]){
               dist[j]=distance+w[i];
               heap.push({dist[j],j});
           }
       }
   }

}

int main( ){
    int s;
   cin>>n>>m>>s;
   
   memset(h,-1,sizeof h);
   while(m--){
       int a,b,c;
       cin>>a>>b>>c;
       add(a,b,c);
   }
   dijkstra();
   
    for(int i=1;i<=n;i++)
    cout<<dist[i]<<' ';
    
    return 0;
    
}
2023/7/16 22:53
加载中...