今天做题碰见无法理解的问题,定义了一个数组
next[300005];
编译报错,说next的引用有歧义
附上错误连接https://www.luogu.com.cn/record/112769295
检查之后没有发现命名冲突,把用到next的地方改为Next,然后编译通过了,
过了部分检查点。
不理解这个编译错误,因此发帖求助,希望得到解答。
也不明白为什么有四个检查点没过,有点太菜了哈哈,也求解答。
附上源代码:
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
const ll N=3e5+5,MAX=0x7fffffffffffffff;
ll dis[N],h[N],to[N],wi[N],Next[N],exist[N],n,m,u,v,w,tot;
void read(ll &a){
ll s=0;
char ch=getchar();
while(ch<'0'||ch>'9'){
ch=getchar();
}
while(ch>='0'&&ch<='9'){
s=(s<<1)+(s<<3)+(ch^48);
ch=getchar();
}
a=s;
}
struct node{
ll dis,index;
bool operator<(const node &b){
return dis<b.dis;
}
void operator=(const node &b){
dis=b.dis;
index=b.index;
}
void swap(node &a,node &b){
ll x=a.dis,y=a.index;
a.dis=b.dis;
a.index=b.index;
b.dis=x;
b.index=y;
}
}q[2*N],now;
class queue{
private:
int index;
public:
queue(){
index=0;
}
void push(node a){
q[++index]=a;
int x=index;
int y=x>>1;
while(q[x]<q[y]){
swap(q[x],q[y]),x=y,y>>=1;
}
}
node pop(){
node re = q[1];
q[1]=q[index--];
int x=1;
int y=x<<1;
while(y<=index){
if(y<index&&q[y+1]<q[y])y++;
else if(q[y].dis<q[x].dis)swap(q[y],q[x]),x=y,y<<=1;
else break;
}
return re;
}
int isvoid(){
return index;
}
};
int main(){
read(n);
read(m);
for(int i=0;i<=N;i++)dis[i]=MAX;
for(int i=0;i<m;i++){
read(u);
read(v);
read(w);
Next[++tot]=h[u];
to[tot]=v;
wi[tot]=w;
h[u]=tot;
}
queue qw;
qw.push((node){0,1});
dis[1]=0;
while(qw.isvoid()){
now = qw.pop();
int mi = now.index;
if(exist[mi])continue;
exist[mi]=1;
for(int t = h[mi];t;t=Next[t]){
int v = to[t];
if(dis[v]>dis[mi]+wi[t]){
dis[v]=dis[mi]+wi[t];
if(!exist[v]){
qw.push((node){dis[v],v});
}
}
}
}
for(int i=1;i<=n;i++){
ll f=(dis[i]==MAX)?-1:dis[i];
cout<<f<<" ";
}
}